Select.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* This Hello World demostrate a simple multithread program */
  2. #include "pal.h"
  3. #include "pal_debug.h"
  4. PAL_HANDLE wakeup;
  5. int thread (void * args)
  6. {
  7. pal_printf("Enter Thread\n");
  8. DkThreadDelayExecution(3000000);
  9. pal_printf("set event\n");
  10. char byte = 0;
  11. DkStreamWrite(wakeup, 0, 1, &byte, NULL);
  12. pal_printf("Leave Thread\n");
  13. return 0;
  14. }
  15. int main() {
  16. pal_printf("Enter Main Thread\n");
  17. PAL_HANDLE handles[3];
  18. handles[0] = DkStreamOpen("pipe:", PAL_ACCESS_RDWR, 0, 0, 0);
  19. handles[1] = DkStreamOpen("pipe:", PAL_ACCESS_RDWR, 0, 0, 0);
  20. handles[2] = DkStreamOpen("pipe:", PAL_ACCESS_RDWR, 0, 0, 0);
  21. wakeup = handles[2];
  22. PAL_HANDLE thd = DkThreadCreate(&thread, NULL);
  23. if (thd == NULL) {
  24. pal_printf("DkThreadCreate failed\n");
  25. return -1;
  26. }
  27. pal_printf("wait on event\n");
  28. PAL_HANDLE hdl = DkObjectsWaitAny(3, handles, NO_TIMEOUT);
  29. if (hdl == wakeup)
  30. pal_printf("events is called\n");
  31. pal_printf("Leave Main Thread\n");
  32. return 0;
  33. }