Select.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. pal_printf("Enter Thread\n");
  7. DkThreadDelayExecution(3000000);
  8. pal_printf("set event\n");
  9. char byte = 0;
  10. DkStreamWrite(wakeup, 0, 1, &byte, NULL);
  11. pal_printf("Leave Thread\n");
  12. return 0;
  13. }
  14. int main() {
  15. pal_printf("Enter Main Thread\n");
  16. PAL_HANDLE handles[3];
  17. handles[0] = DkStreamOpen("pipe:", PAL_ACCESS_RDWR, 0, 0, 0);
  18. handles[1] = DkStreamOpen("pipe:", PAL_ACCESS_RDWR, 0, 0, 0);
  19. handles[2] = DkStreamOpen("pipe:", PAL_ACCESS_RDWR, 0, 0, 0);
  20. wakeup = handles[2];
  21. PAL_HANDLE thd = DkThreadCreate(&thread, NULL);
  22. if (thd == NULL) {
  23. pal_printf("DkThreadCreate failed\n");
  24. return -1;
  25. }
  26. pal_printf("wait on event\n");
  27. PAL_HANDLE hdl = DkObjectsWaitAny(3, handles, NO_TIMEOUT);
  28. if (hdl == wakeup)
  29. pal_printf("events is called\n");
  30. pal_printf("Leave Main Thread\n");
  31. return 0;
  32. }