Template:OS2API Example CritSec: Difference between revisions
Appearance
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..." |
mNo edit summary |
||
Line 7: | Line 7: | ||
int main(VOID) | int main(VOID) | ||
{ | |||
APIRET rc = NO_ERROR; /* Return code */ | 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; | |||
} | |||
</code> | </code> |
Latest revision as of 18:28, 2 May 2020
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;
}