Thread.c 908 B

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