home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l350 / 3.ddi / EXAMPLES / WINDOWS / TASKTEST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-30  |  946 b   |  39 lines

  1. /* 
  2. TASKTEST.C
  3. */ 
  4.  
  5. #include <stdlib.h> 
  6. #include <stdio.h> 
  7. #include <time.h> 
  8. #include "wintask.h" 
  9.  
  10. void wait(int seconds) 
  11.     time_t t1, t2; 
  12.     time(&t1); 
  13.     while ((time(&t2)-t1) < seconds) 
  14.         Yield(); 
  15.  
  16. void fail(char *s) { puts(s); exit(1); } 
  17.  
  18. main() 
  19.     int dummy; 
  20.     if (! win3e(&dummy, &dummy)) 
  21.         fail("This program requires Windows 3.0 Enhanced mode"); 
  22.     printf("VM Id: %u\n", VMId()); 
  23.     wait(5);  // give user chance to switch to other task 
  24.     fputs("Try to do something...", stdout); 
  25.     fflush(stdout); 
  26.     Yield();  // Yield so task that produces output gets to run! 
  27.     BeginCriticalSection(); 
  28.     /* No other Windows tasks can run; also can't switch  
  29.        away with mouse or ALT ESC or CTRL ESC! */ 
  30.     wait(5); 
  31.     EndCriticalSection(); 
  32.     /* Now other tasks can run; can also switch away again */ 
  33.     puts("done"); 
  34.     return 0; 
  35.