Event.c 1003 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "pal.h"
  2. #include "pal_debug.h"
  3. static PAL_HANDLE event1;
  4. int count = 0;
  5. int thread_func(void* args) {
  6. DkThreadDelayExecution(1000);
  7. pal_printf("In thread 1\n");
  8. while (count < 100)
  9. count++;
  10. DkEventSet(event1);
  11. DkThreadExit(/*clear_child_tid=*/NULL);
  12. return 0; /* NOTREACHED */
  13. }
  14. int main(int argc, char** argv) {
  15. pal_printf("Enter main thread\n");
  16. PAL_HANDLE thd1;
  17. event1 = DkNotificationEventCreate(0);
  18. if (!event1) {
  19. pal_printf("DkNotificationEventCreate failed\n");
  20. return -1;
  21. }
  22. thd1 = DkThreadCreate(&thread_func, 0);
  23. if (!thd1) {
  24. pal_printf("DkThreadCreate failed\n");
  25. return -1;
  26. }
  27. /* wait till thread thd1 is done */
  28. DkSynchronizationObjectWait(event1, NO_TIMEOUT);
  29. if (count != 100)
  30. return -1;
  31. /* this wait should return immediately */
  32. DkSynchronizationObjectWait(event1, NO_TIMEOUT);
  33. pal_printf("Success, leave main thread\n");
  34. return 0;
  35. }