Jump to content

Template:OS2API Example CritSec: Difference between revisions

From EDM2
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..."
(No difference)

Revision as of 16:19, 15 January 2019

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