Yield.c 854 B

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