Difference between revisions of "DosExitCritSec"
m (Ak120 moved page OS2 API:CPI:DosExitCritSec to DosExitCritSec) |
m |
||
Line 1: | Line 1: | ||
− | |||
Restores normal thread dispatching for the current process. | Restores normal thread dispatching for the current process. | ||
==Syntax== | ==Syntax== | ||
− | + | DosExitCritSec ( ) | |
− | + | ||
− | + | ||
− | |||
− | |||
− | |||
− | |||
− | |||
==Parameters== | ==Parameters== | ||
+ | none | ||
==Return Code== | ==Return Code== | ||
ulrc (APIRET) - returns | ulrc (APIRET) - returns | ||
− | |||
DosExitCritSec returns one of the following values: | DosExitCritSec returns one of the following values: | ||
− | |||
* 0 NO_ERROR | * 0 NO_ERROR | ||
* 309 ERROR_INVALID_THREADID | * 309 ERROR_INVALID_THREADID | ||
* 485 ERROR_CRITSEC_UNDERFLOW | * 485 ERROR_CRITSEC_UNDERFLOW | ||
+ | |||
==Remarks== | ==Remarks== | ||
− | DosExitCritSec is used following DosEnterCritSec to restore normal thread switching to the threads of a process. | + | DosExitCritSec is used following [[DosEnterCritSec]] to restore normal thread switching to the threads of a process. |
A count is maintained of the number of times DosEnterCritSec is issued without a corresponding DosExitCritSec. The count is incremented by DosEnterCritSec, and decremented by DosExitCritSec. Normal thread dispatching is not restored until the count is zero. | A count is maintained of the number of times DosEnterCritSec is issued without a corresponding DosExitCritSec. The count is incremented by DosEnterCritSec, and decremented by DosExitCritSec. Normal thread dispatching is not restored until the count is zero. | ||
Line 70: | Line 62: | ||
</PRE> | </PRE> | ||
− | |||
− | |||
− | |||
+ | ==Related Functions== | ||
+ | * [[DosCreateThread]] | ||
+ | * [[DosEnterCritSec]] | ||
− | [[Category: | + | [[Category:Dos]] |
Revision as of 05:38, 13 February 2017
Restores normal thread dispatching for the current process.
Syntax
DosExitCritSec ( )
Parameters
none
Return Code
ulrc (APIRET) - returns
DosExitCritSec returns one of the following values:
- 0 NO_ERROR
- 309 ERROR_INVALID_THREADID
- 485 ERROR_CRITSEC_UNDERFLOW
Remarks
DosExitCritSec is used following DosEnterCritSec to restore normal thread switching to the threads of a process.
A count is maintained of the number of times DosEnterCritSec is issued without a corresponding DosExitCritSec. The count is incremented by DosEnterCritSec, and decremented by DosExitCritSec. Normal thread dispatching is not restored until the count is zero.
The outstanding count is maintained in a word. If an underflow occurs (the count is decremented below zero), the count is set to zero, no operation is performed, and the request returns with ERROR_CRITSEC_UNDERFLOW.
ERROR_INVALID_THREADID is returned when an invalid attempt is made to exit a critical section of code in a signal handler or exception handler.
ERROR_INVALID_THREADID is also returned when a dynamic link library (DLL) routine incorrectly issues DosExitCritSec.
Example Code
This example shows how a thread can enter and exit a critical section of code.
#define INCL_DOSPROCESS /* Process values */ #define INCL_DOSERRORS /* Error values */ #include <os2.h> #include <stdio.h> int main(VOID) { APIRET rc = NO_ERROR; /* Return code */ rc = DosEnterCritSec(); if (rc != NO_ERROR) { printf("DosEnterCritSec error: return code = %u\n",rc); return 1; } /***********************************************/ /* Add critical section code here. While this */ /* code is running, all other threads are */ /* stopped. CALL NO LIBRARY OR OS/2 FUNCTIONS */ /* HERE UNLESS YOU KNOW THEY DO NOT REQUIRE */ /* ACTION BY ANOTHER THREAD IN THE PROCESS. */ /***********************************************/ rc = DosExitCritSec(); if (rc != NO_ERROR) { printf("DosExitCritSec error: return code = %u\n",rc); return 1; } return NO_ERROR; }