Difference between revisions of "DosExitCritSec"

From EDM2
Jump to: navigation, search
(Created page with "==Description== Restores normal thread dispatching for the current process. ==Syntax== <PRE> #define INCL_DOSPROCESS #include <os2.h> APIRET ulrc; Return Code.: u...")
 
m (Example Code)
 
(2 intermediate revisions by one user not shown)
Line 1: Line 1:
==Description==
 
 
Restores normal thread dispatching for the current process.
 
Restores normal thread dispatching for the current process.
  
 
==Syntax==
 
==Syntax==
<PRE>
+
DosExitCritSec ( )
#define INCL_DOSPROCESS
+
#include <os2.h>
+
  
APIRET    ulrc;  /*  Return Code. */
 
 
ulrc = DosExitCritSec();
 
 
</PRE>
 
 
==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 34: Line 26:
  
 
==Example Code==
 
==Example Code==
This example shows how a thread can enter and exit a critical section of code.
+
{{OS2API Example CritSec}}
<PRE>
+
#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;
 
    }
 
 
</PRE>
 
 
==Related Functions==
 
==Related Functions==
* [[OS2 API:CPI:DosCreateThread|DosCreateThread]]
+
* [[DosCreateThread]]
* [[OS2 API:CPI:DosEnterCritSec|DosEnterCritSec]]
+
* [[DosEnterCritSec]]
 
+
  
[[Category:The OS/2 API Project]]
+
[[Category:Dos]]

Latest revision as of 15:20, 15 January 2019

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 enters and exits 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