Jump to content

Template:OS2API Example CritSec

From EDM2
Revision as of 17:19, 15 January 2019 by Ak120 (talk | contribs) (Created page with "This example shows how a thread enters and exits a critical section of code. <code> #define INCL_DOSPROCESS Process values: #define INCL_DOSERRORS /* Error v...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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