DosEnterCritSec (OS/2 1.x)
This call disables thread switching for the current process.
- rc (USHORT) - return
- Return code descriptions are:
- 0 NO_ERROR
- 484 ERROR_CRITSEC_OVERFLOW
DosEnterCritSec causes other threads in the process to block themselves and give up their time slice. After a DosEnterCritSec request is made, no dynamic link calls should be made until the corresponding DosExitCritSec call is completed.
If a signal occurs, thread 1 begins execution to process the signal even though another thread in the process has a DosEnterCritSec active. (Thread 1 of a process is its initial thread of execution, not a thread created with the DosCreateThread call.) Any processing done by thread 1 to satisfy the signal must not include accessing the critical resource intended to be protected by the DosEnterCritSec request.
A count is maintained of the number of times a DosEnterCritSec request is made without a corresponding DosExitCritSec. The count is incremented by DosEnterCritSec and decremented by DosExitCritSec. Normal thread dispatching is not restored until the count is 0. The outstanding DosEnterCritSec count is maintained in a word. If overflow occurs, the count is set to the maximum value, no operation is performed, and the request returns with an error.
A thread can also execute code without having to give up time slices to other threads in its process if it requests a priority class that is higher than those of the other threads. A thread's priority is examined and changed with DosGetPrty and DosSetPrty.
#define INCL_DOSPROCESS USHORT rc = DosEnterCritSec(VOID); USHORT rc; /* return code */
EXTRN DosEnterCritSec:FAR INCL_DOSPROCESS EQU 1 CALL DosEnterCritSec Returns WORD
This example enters a section that will not be pre-empted, performs a simple task, and then exits quickly.
#define INCL_DOSPROCESS USHORT flag; DosEnterCritSec(); /* Enter critical code section */ flag = TRUE; /* Perform some work */ DosExitCritSec(); /* Exit critical code section */