home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_01 / 2n01008a < prev    next >
Text File  |  1990-12-03  |  802b  |  52 lines

  1. /* threads1.c */
  2. /* Listing 1 -- An example of an alarm thread */
  3.  
  4. #include <conio.h>
  5. #include <process.h>
  6. #define INCL_DOSPROCESS
  7. #include <os2.h>
  8.  
  9. USHORT beeperThreadID;
  10. #define BEEPER_SSIZE 3000
  11. void beeper( void *arg);
  12.  
  13. int Horn = 0;
  14.  
  15. void main(void)
  16. {
  17.   char c;
  18.  
  19.   beeperThreadID = _beginthread( beeper, NULL,
  20.       BEEPER_SSIZE, NULL);
  21.  
  22.   while (c= (char) getch() )
  23.     {
  24.     if (c == 'a')
  25.       Horn = 1;
  26.     else if (c == 'c')
  27.       Horn = 0;
  28.     else if (c == 'x')
  29.       break;
  30.     }
  31. }
  32.  
  33.    /* "arg" here is a dummy --
  34.        just to satify the compiler */
  35.  
  36. void beeper( void *arg)
  37. {
  38.   while (1)
  39.     {
  40.     if (Horn)
  41.       {
  42.       DosBeep( 1000, 125);
  43.       DosBeep(  750, 125);
  44.       }
  45.     else
  46.       {
  47.       DosSleep( 250L);
  48.       }
  49.     }
  50. }
  51.  
  52.