Thread.c 913 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* This Hello World demostrate a simple multithread program */
  2. #include "pal.h"
  3. #include "pal_debug.h"
  4. int thread_1 (void * args)
  5. {
  6. pal_printf("Enter Thread 1\n");
  7. DkThreadDelayExecution(3000);
  8. pal_printf("Leave Thread 1\n");
  9. return 0;
  10. }
  11. int thread_2 (void * args)
  12. {
  13. pal_printf("Enter Thread 2\n");
  14. pal_printf("Parent do suspension\n");
  15. DkThreadDelayExecution(3000);
  16. pal_printf("Parent do reload\n");
  17. pal_printf("Leave Thread 2\n");
  18. return 0;
  19. }
  20. int main() {
  21. pal_printf("Enter Main Thread\n");
  22. PAL_HANDLE thd1, thd2;
  23. thd1 = DkThreadCreate(&thread_1, NULL);
  24. if (thd1 == NULL) {
  25. pal_printf("DkThreadCreate failed\n");
  26. return -1;
  27. }
  28. thd2 = DkThreadCreate(&thread_2, NULL);
  29. if (thd2 == NULL) {
  30. pal_printf("DkThreadCreate failed\n");
  31. return -1;
  32. }
  33. pal_printf("Leave Main Thread\n");
  34. return 0;
  35. }