/*
 *      demo showing multi-threaded debugging
 */
#include <stdio.h>
#include <process.h>
#define INCL_DOSPROCESS
#include <os2.h>

int x;
void thread()
{
   int i;
        for (i=0;i<100;i++) {
           DosEnterCritSec();
           x=x+1;
           printf("thread: x= %d\n",x);
           DosExitCritSec();
          }
}

void main()
{
   TID tid;
   PFNTHREAD taddr;
   ULONG targ;
   ULONG tflags;
   ULONG stack;
   APIRET rc;
   int i;

   tflags = 0;              // start thread immediately
   stack  = 4096;
   taddr  = &thread;
   targ = 0;
   if ((rc = DosCreateThread(&tid,taddr,targ,tflags,stack)) != 0)
      printf("DosCreateThread error!\n");
   else {
        for (i=0;i<100;i++) {
           DosEnterCritSec();
           x=x-1;
           printf("main: x= %d\n",x);
           DosExitCritSec();
          }
       }
}

