DosExitCritSec

From EDM2
Revision as of 05:38, 13 February 2017 by Ak120 (Talk | contribs)

Jump to: navigation, search

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;
    }

Related Functions