/* threads1.c */
/* Listing 1 -- An example of an alarm thread */

#include <conio.h>
#include <process.h>
#define INCL_DOSPROCESS
#include <os2.h>

USHORT beeperThreadID;
#define BEEPER_SSIZE 3000
void beeper( void *arg);

int Horn = 0;

void main(void)
{
  char c;

  beeperThreadID = _beginthread( beeper, NULL,
      BEEPER_SSIZE, NULL);

  while (c= (char) getch() )
    {
    if (c == 'a')
      Horn = 1;
    else if (c == 'c')
      Horn = 0;
    else if (c == 'x')
      break;
    }
}

   /* "arg" here is a dummy --
       just to satify the compiler */

void beeper( void *arg)
{
  while (1)
    {
    if (Horn)
      {
      DosBeep( 1000, 125);
      DosBeep(  750, 125);
      }
    else
      {
      DosSleep( 250L);
      }
    }
}

