•  Back 
  •  MiNT 
  •  Index 
  •  Tree View 
  •  Cross references 
  •  %About 
  •  Show info about hypertext 
  •  View a new file 
Topic       : The ATARI Compendium
Author      : Scott Sanders / JAY Software
Version     : 1.25 (20/6/2003)
Subject     : Documentation
Nodes       : 1117
Index Size  : 32614
HCP-Version : 6
Compiled on : Atari
@charset    : UTF-8
@lang       : en
@default    : 
@help       : %About
@options    : +g -i -t4 +y +z
@width      : 100
View Ref-File
                                 Threads


It is possible under MiNT to split a single process into 'threads'. These
threads continue execution independently as unique processes. The Pfork()
and Pvfork() calls are used to split a process into threads.

The original process that calls Pfork() or Pvfork() is considered the
parent and the newly created process is considered the child.

Child processes created with Pfork() share the TEXT segment of the parent,
however they are given a copy of the DATA and BSS segments. Both the parent
and child execute concurrently.

Child processes created with Pvfork() share the entire program code and
data space including  the processor stack. The parent process is suspended
until the child exits or calls Pexec()'s mode 200.

Child processes started with either call may make GEM calls but a child
process started with Pfork() must call appl_init() to force GEM to uniquely
recognize it as an independent process. This is not necessary with Pvfork()
because all program variables are shared.

The following is a simple example of using a thread in a GEM application:

VOID
UserSelectedPrint( VOID )
{
    /* Prevent the user from editing buffer being printed. */
    LockBufferFromEdits();

    if( Pfork() == 0)
    {
            /* Child enters here */

            appl_init();                    /* Required for GEM threads. */

            DisplayPrintingWindow();        /* Do our task. */
            PrintBuffer();

            /* Send an AES message to the parent telling it to unlock buffer. */
            SendCompletedMessageToParent();

            /* Cleanup and exit thread. */
            appl_exit();
            Pterm( 0 );
    }

    /* Parent returns and continues normal execution. */
}