Event.c 1.1 KB

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