home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / except2x.zip / exittest.c < prev    next >
Text File  |  1994-02-17  |  2KB  |  61 lines

  1. /**********************************************************************/
  2. /*                                                                    */
  3. /*  SSS                                                               */
  4.  
  5. #include <conio.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8.  
  9. void TrapFunc(void);
  10. #define INCL_BASE
  11. #define INCL_DOSPROCESS
  12. #define INCL_DOSSEMAPHORES   /* Semaphore values */
  13. #include <os2.h>
  14.  
  15.  
  16. void KeyboardThread(PVOID args) {
  17.     printf("Keyboard read thread\n");
  18.     getch();
  19.     printf("Keyboard read\n");
  20. }
  21. void SemWaitThread(PVOID args) {
  22.     HEV  WaitSem= 0;
  23.     ULONG Count;
  24.     DosCreateEventSem(0,&WaitSem,0,FALSE);
  25.     DosResetEventSem(WaitSem,&Count);
  26.     printf("Wait semaphore thread\n");
  27.     DosWaitEventSem(WaitSem,SEM_INDEFINITE_WAIT);
  28.     printf("Wait semaphore ended\n");
  29. }
  30. void QueueThread(PVOID args) {
  31.     HQUEUE hq;
  32.     REQUESTDATA Request;
  33.     ULONG cbData;
  34.     PVOID pbuf;
  35.     APIRET rc;
  36.     BYTE priority;
  37.     rc=DosCreateQueue( &hq,QUE_FIFO,"\\QUEUES\\TESTEXIT");
  38.     printf("Queue Created rc=%d\n",rc);
  39.     printf("Now reading queue\n");
  40.     rc=DosReadQueue(hq,&Request, &cbData, &pbuf,0,DCWW_WAIT,
  41.                                     &priority, 0);
  42.     printf("queue read\n");
  43. }
  44. void SleepingThread(PVOID args) {
  45.     printf("Thread Sleeping\n");
  46.     DosSleep(100000L);
  47. }
  48. VOID  APIENTRY  ForceExit(VOID);
  49. main()
  50. {
  51.     _beginthread( SleepingThread,NULL, 4192,NULL );
  52.     _beginthread( QueueThread   ,NULL, 4192,NULL );
  53.     _beginthread( SemWaitThread ,NULL, 4192,NULL );
  54.     _beginthread( KeyboardThread,NULL, 4192,NULL );
  55.     printf("Waiting 2 seconds in thread 1\n");
  56.     DosSleep(2000L);
  57.     printf("Before ForceExit\n");
  58.     ForceExit();
  59.     printf("After ForceExit\n");  /* Should never be displayed */
  60. }
  61.