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

  1. /* threads2.c */
  2. /* Listing 2 -- An example of an alarm thread, with higher priority */
  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.   DosSetPrty( PRTYS_THREAD,
  39.               PRTYC_TIMECRITICAL,
  40.               PRTYD_MINIMUM, 0);
  41.   while (1)
  42.     {
  43.     if (Horn)
  44.       {
  45.       DosBeep( 1000, 125);
  46.       DosBeep(  750, 125);
  47.       }
  48.     else
  49.       {
  50.       DosSleep( 250L);
  51.       }
  52.     }
  53. }
  54.  
  55.