Event.c 958 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* This Hello World demostrate a simple multithread program */
  2. #include "pal.h"
  3. #include "pal_debug.h"
  4. static PAL_HANDLE event1;
  5. int count = 0;
  6. int thread_1(void* args) {
  7. DkThreadDelayExecution(1000);
  8. pal_printf("In Thread 1\n");
  9. while (count < 100) {
  10. count++;
  11. }
  12. DkEventSet(event1);
  13. DkThreadExit(/*clear_child_tid=*/NULL);
  14. return 0;
  15. }
  16. int main(int argc, char** argv) {
  17. pal_printf("Enter Main Thread\n");
  18. PAL_HANDLE thd1;
  19. event1 = DkNotificationEventCreate(0);
  20. if (event1 == NULL) {
  21. pal_printf("DkNotificationEventCreate failed\n");
  22. return -1;
  23. }
  24. thd1 = DkThreadCreate(&thread_1, 0);
  25. if (thd1 == NULL) {
  26. pal_printf("DkThreadCreate failed\n");
  27. return -1;
  28. }
  29. DkObjectsWaitAny(1, &event1, NO_TIMEOUT);
  30. if (count < 100)
  31. return -1;
  32. DkObjectsWaitAny(1, &event1, NO_TIMEOUT);
  33. pal_printf("Leave Main Thread\n");
  34. return 0;
  35. }