--- os2sdk/demos/examples/critsec/critsec.c 2018/08/09 12:25:13 1.1 +++ os2sdk/demos/examples/critsec/critsec.c 2018/08/09 12:26:17 1.1.1.2 @@ -1,17 +1,17 @@ /* - * Example of DOSENTERCRITSEC/DOSEXITCRITSEC usage. + * Example of DosEnterCritSec/DosExitCritSec usage. * - * After a call to DOSENTERCRITSEC, a thread can be sure that it is the + * After a call to DosEnterCritSec, a thread can be sure that it is the * only one in the current process running. * * Note that critical sections, like thread suspensions, are overridden * by signals, so any signal handlers must be written so as not to * affect the resource protected by the critical section. * - * The effect of DOSENTERCRITSEC differs from the use of semaphores for + * The effect of DosEnterCritSec differs from the use of semaphores for * exclusion between threads. Semaphores allow other threads to generally * run, and only blocks them when they hit a locked region. This is the - * generally preferable way to write a program. DOSENTERCRITSEC is much + * generally preferable way to write a program. DosEnterCritSec is much * more drastic since it freezes all other threads, regardless of whether * they are in a particular critical section or not. In effect this * function makes the entire program a critical section, and claims it for @@ -25,11 +25,14 @@ * * compile as: cl -Ox -Zp -AL -Lp critsec.c * - * Copyright (C) Microsoft Corp. 1986 + * Created by Microsoft Corp. 1986 */ -#include -#include +#define INCL_SUB +#define INCL_DOSPROCESS + +#include +#include #include #include #include @@ -41,8 +44,9 @@ int flag; void main() { - char far *stkptr; - unsigned thread_id, res; + PCHAR stkptr; + TID thread_id; + unsigned res; flag = 0; @@ -50,37 +54,37 @@ void main() stkptr = (char *)malloc(STACK_SIZE) + STACK_SIZE; /* create another thread */ - res = DOSCREATETHREAD(f_thread, &thread_id, stkptr); + res = DosCreateThread(f_thread, &thread_id, stkptr); assert(res == 0); /* wait for the sub-thread to set the flag */ while (flag == 0) { - DOSSLEEP((long)100); + DosSleep(100L); /* * Remember: testing of the flag must be atomic too. * otherwize the flag will be set !0 between the test and * the printf! */ - DOSENTERCRITSEC(); + DosEnterCritSec(); if (flag == 0) printf("Thread 0: flag is still zero\n"); - DOSEXITCRITSEC(); + DosExitCritSec(); } printf("Thread 0: flag was finally set\n"); fflush(stdout); - DOSEXIT(1,0); + DosExit(EXIT_PROCESS,0); } void far f_thread() { /* set the flag */ - DOSSLEEP((long)1000); - DOSENTERCRITSEC(); + DosSleep(1000L); + DosEnterCritSec(); flag = 1; - VIOWRTTTY("Thread1: I am setting the flag\r\n", 33, 0); - DOSEXITCRITSEC(); + VioWrtTTy("Thread1: I am setting the flag\r\n", 33, 0); + DosExitCritSec(); /* exit this thread */ - DOSEXIT(0,0); + DosExit(EXIT_THREAD,0); }