Thread.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. int thread_1 (void * args)
  7. {
  8. pal_printf("Enter Thread 1\n");
  9. DkThreadDelayExecution(3000);
  10. pal_printf("Leave Thread 1\n");
  11. return 0;
  12. }
  13. int thread_2 (void * args)
  14. {
  15. pal_printf("Enter Thread 2\n");
  16. pal_printf("Parent do suspension\n");
  17. DkThreadDelayExecution(3000);
  18. pal_printf("Parent do reload\n");
  19. pal_printf("Leave Thread 2\n");
  20. return 0;
  21. }
  22. int main() {
  23. pal_printf("Enter Main Thread\n");
  24. PAL_HANDLE thd1, thd2;
  25. thd1 = DkThreadCreate(&thread_1, NULL);
  26. if (thd1 == NULL) {
  27. pal_printf("DkThreadCreate failed\n");
  28. return -1;
  29. }
  30. thd2 = DkThreadCreate(&thread_2, NULL);
  31. if (thd2 == NULL) {
  32. pal_printf("DkThreadCreate failed\n");
  33. return -1;
  34. }
  35. pal_printf("Leave Main Thread\n");
  36. return 0;
  37. }