[Toc][Index]

DosCreateThread


Bindings:  C, MASM 

This call creates an asynchronous thread of execution under the current 
process. 
 DosCreateThread     (PgmAddress, ThreadIDWord, NewThreadStack) 
 
 PgmAddress (PFNTHREAD) - input 
    Address within program module where new thread begins execution. This 
    address must not be in an IOPL segment. 
 ThreadIDWord (PTID) - output 
    Address of thread ID of the new thread. 
 NewThreadStack (PBYTE) - input 
    Address of the new thread's stack. 
 rc (USHORT) - return 
    Return code descriptions are: 
    0         NO_ERROR 
    8         ERROR_NOT_ENOUGH_MEMORY 
    89        ERROR_NO_PROC_SLOTS 
    212       ERROR_LOCKED 
 
 Remarks 
 OS/2 creates the first thread of a process when it starts the executable 
 file.  This thread is dispatched with a regular class priority. To start 
 another thread of execution under the current process, the current thread 
 allocates stack memory and issues DosCreateThread. Upon generation of the 
 far call, the thread's initial dispatch point is the address specified 
 for PgmAddress. The started thread has a unique stack and register 
 context and the same priority as the requesting thread. 
 Note:  The minimum available space on the stack for a thread calling an 
        operating system function must be 4K bytes. 
 
 A thread's stack, register context, and priority is the only information 
 maintained by OS/2 that is specific to the thread. The thread shares 
 resources with other threads of the process. Any thread in the process 
 can open a file or device, and any other thread can issue a read or write 
 to that handle. This is also true for pipes, queues, and system 
 semaphores. 
 The address passed as the NewThreadStack value must be the address of the 
 highest byte in the stack. This value is loaded into the SS:PP registers 
 before starting the new thread. 
 A thread started with DosCreateThread terminates upon return of this call 
 or when a DosExit is issued. Any thread can temporarily stop the 
 execution of other threads in its process with DosSuspendThread, 
 DosResumeThread,  DosEnterCritSec, and DosExitCritSec calls.  Any thread 
 can also examine and change the priority at which it and other threads 
 execute with DosGetPrty and  DosSetPrty. 
 Note:  DosCreateThread cannot be issued from within a segment that has 
        I/O privilege (IOPL).  If the new thread entry point is in an IOPL 
        code segment, a general protection fault is generated, and the 
        process is terminated. 
        All code segments execute at a privilege level. Segments for OS/2 
        applications usually execute at privilege level 3. However, if an 
        application has an IOPL code segment that is executing at 
        privilege level 2 and has to start another thread of execution, 
        DosCallback can be issued from the IOPL segment to invoke a 
        privilege level 3 segment.  But before the DosCreateThread request 
        is made, the IOPL segment's stack must be resized in the privilege 
        level 3 segment by a call to DosR2StackRealloc. For more 
        information on IOPL code segments, see IBM Operating System/2 
        Version 1.2 I/O Subsystems And Device Support Volume 1. 
 

Created using Inf-PHP v.2 (c) 2003 Yuri Prokushev
Created using Inf-HTML v.0.9b (c) 1995 Peter Childs