Select.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "pal.h"
  2. #include "pal_debug.h"
  3. PAL_HANDLE wakeup;
  4. int thread_func(void* args) {
  5. pal_printf("Enter thread\n");
  6. DkThreadDelayExecution(3000000);
  7. pal_printf("Thread sets event\n");
  8. char byte = 0;
  9. DkStreamWrite(wakeup, 0, 1, &byte, NULL);
  10. pal_printf("Leave thread\n");
  11. return 0;
  12. }
  13. int main(int argc, char** argv) {
  14. pal_printf("Enter main thread\n");
  15. PAL_HANDLE handles[3];
  16. handles[0] = DkStreamOpen("pipe:", PAL_ACCESS_RDWR, 0, 0, 0);
  17. handles[1] = DkStreamOpen("pipe:", PAL_ACCESS_RDWR, 0, 0, 0);
  18. handles[2] = DkStreamOpen("pipe:", PAL_ACCESS_RDWR, 0, 0, 0);
  19. wakeup = handles[2];
  20. PAL_HANDLE thd = DkThreadCreate(&thread_func, NULL);
  21. if (!thd) {
  22. pal_printf("DkThreadCreate failed\n");
  23. return -1;
  24. }
  25. pal_printf("Waiting on event\n");
  26. PAL_FLG events[3] = {PAL_WAIT_READ, PAL_WAIT_READ, PAL_WAIT_READ};
  27. PAL_FLG revents[3] = {0, 0, 0};
  28. PAL_BOL polled = DkStreamsWaitEvents(3, handles, events, revents, NO_TIMEOUT);
  29. if (!polled) {
  30. pal_printf("DkStreamsWaitEvents did not return any events\n");
  31. return -1;
  32. }
  33. if (revents[2])
  34. pal_printf("Event was called\n");
  35. pal_printf("Leave main thread\n");
  36. return 0;
  37. }