Select.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. /* This Hello World demostrate a simple multithread program */
  4. #include "pal.h"
  5. #include "pal_debug.h"
  6. PAL_HANDLE wakeup;
  7. int thread (void * args)
  8. {
  9. pal_printf("Enter Thread\n");
  10. DkThreadDelayExecution(3000000);
  11. pal_printf("set event\n");
  12. char byte = 0;
  13. DkStreamWrite(wakeup, 0, 1, &byte, NULL);
  14. pal_printf("Leave Thread\n");
  15. return 0;
  16. }
  17. int main() {
  18. pal_printf("Enter Main Thread\n");
  19. PAL_HANDLE handles[3];
  20. handles[0] = DkStreamOpen("pipe:", PAL_ACCESS_RDWR, 0, 0, 0);
  21. handles[1] = DkStreamOpen("pipe:", PAL_ACCESS_RDWR, 0, 0, 0);
  22. handles[2] = DkStreamOpen("pipe:", PAL_ACCESS_RDWR, 0, 0, 0);
  23. wakeup = handles[2];
  24. PAL_HANDLE thd = DkThreadCreate(&thread, NULL, 0);
  25. if (thd == NULL) {
  26. pal_printf("DkThreadCreate failed\n");
  27. return -1;
  28. }
  29. pal_printf("wait on event\n");
  30. PAL_HANDLE hdl = DkObjectsWaitAny(3, handles, NO_TIMEOUT);
  31. if (hdl == wakeup)
  32. pal_printf("events is called\n");
  33. pal_printf("Leave Main Thread\n");
  34. return 0;
  35. }