Event.c 930 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. {
  8. DkThreadDelayExecution(1000);
  9. pal_printf("In Thread 1\n");
  10. while (count < 100)
  11. count++;
  12. DkEventSet(event1);
  13. DkThreadExit();
  14. return 0;
  15. }
  16. int main (int argc, char ** argv)
  17. {
  18. pal_printf ("Enter Main Thread\n");
  19. PAL_HANDLE thd1;
  20. event1 = DkNotificationEventCreate(0);
  21. if (event1 == NULL) {
  22. pal_printf("DkNotificationEventCreate failed\n");
  23. return -1;
  24. }
  25. thd1 = DkThreadCreate(&thread_1, 0);
  26. if (thd1 == NULL) {
  27. pal_printf("DkThreadCreate failed\n");
  28. return -1;
  29. }
  30. DkObjectsWaitAny(1, &event1, NO_TIMEOUT);
  31. if (count < 100)
  32. return -1;
  33. DkObjectsWaitAny(1, &event1, NO_TIMEOUT);
  34. pal_printf("Leave Main Thread\n");
  35. return 0;
  36. }