Yield.c 861 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "pal.h"
  2. #include "pal_debug.h"
  3. PAL_HANDLE parent_thread, child_thread;
  4. int child (void * args)
  5. {
  6. int i;
  7. pal_printf("Enter Child Thread\n");
  8. for (i = 0 ; i < 100 ; i++) {
  9. DkThreadDelayExecution(3000);
  10. DkThreadResume(parent_thread);
  11. pal_printf("parent yielded\n");
  12. }
  13. pal_printf("Leave Child Thread\n");
  14. return 0;
  15. }
  16. int main (void)
  17. {
  18. int i;
  19. pal_printf("Enter Parent Thread\n");
  20. parent_thread = pal_control.first_thread;
  21. child_thread = DkThreadCreate(&child, NULL);
  22. if (child_thread == NULL) {
  23. pal_printf("DkThreadCreate failed\n");
  24. return -1;
  25. }
  26. for (i = 0 ; i < 100 ; i++) {
  27. DkThreadDelayExecution(3000);
  28. DkThreadResume(child_thread);
  29. pal_printf("child yielded\n");
  30. }
  31. pal_printf("Leave Parent Thread\n");
  32. return 0;
  33. }