Yield.c 1.0 KB

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