Successfully reported this slideshow.
Your SlideShare is downloading. ×

CTF問題解説 OSのタスク切換え

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
Programming in C
Programming in C
Loading in …3
×

Check these out next

1 of 15 Ad
Advertisement

More Related Content

Advertisement

CTF問題解説 OSのタスク切換え

  1. 1. 11 8 21
  2. 2. 11 8 21
  3. 3. void main1(int arg) void main2(int arg) void main3(int arg) { { { printf("%d", arg); printf("%d", arg); printf("%d", arg); printf("A"); task_change(); printf("G"); task_change(); printf("C"); task_change(); task_change(); task_change(); printf("H"); printf("B"); printf("D"); task_end(); } task_change(); printf("I"); printf("E"); } task_change(); printf("F"); } 11 8 21
  4. 4. void main1(int arg) void main2(int arg) void main3(int arg) { { { printf("%d", arg); printf("%d", arg); printf("%d", arg); printf("A"); task_change(); printf("G"); task_change(); printf("C"); task_change(); task_change(); task_change(); printf("H"); printf("B"); printf("D"); task_end(); } task_change(); printf("I"); printf("E"); } task_change(); printf("F"); } 11 8 21
  5. 5. void main1(int arg) void main2(int arg) void main3(int arg) { { { printf("%d", arg); printf("%d", arg); printf("%d", arg); printf("A"); task_change(); printf("G"); task_change(); printf("C"); task_change(); task_change(); task_change(); printf("H"); printf("B"); printf("D"); task_end(); } task_change(); printf("I"); printf("E"); } task_change(); printf("F"); } 11 8 21
  6. 6. void main1(int arg) void main2(int arg) void main3(int arg) { { { printf("%d", arg); printf("%d", arg); printf("%d", arg); printf("A"); task_change(); printf("G"); task_change(); printf("C"); task_change(); task_change(); task_change(); printf("H"); printf("B"); printf("D"); task_end(); } task_change(); printf("I"); printf("E"); } task_change(); printf("F"); } 11 8 21
  7. 7. void main1(int arg) void main2(int arg) void main3(int arg) { { { printf("%d", arg); printf("%d", arg); printf("%d", arg); printf("A"); task_change(); printf("G"); task_change(); printf("C"); task_change(); task_change(); task_change(); printf("H"); printf("B"); printf("D"); task_end(); } task_change(); printf("I"); printf("E"); } task_change(); printf("F"); } 11 8 21
  8. 8. void main1(int arg) void main2(int arg) void main3(int arg) { { { printf("%d", arg); printf("%d", arg); printf("%d", arg); printf("A"); task_change(); printf("G"); task_change(); printf("C"); task_change(); task_change(); task_change(); printf("H"); printf("B"); printf("D"); task_end(); } task_change(); printf("I"); printf("E"); } task_change(); printf("F"); } 11 8 21
  9. 9. func_t task_main[] = { main1, main2, main3 }; void schedule() { ... for (i = 0; i < TASKNUM; i++) { n = (n + 1) % TASKNUM; current = &task[n]; ... 11 8 21
  10. 10. func_t task_main[] = { main1, main2, main3 }; void schedule() { ... for (i = 0; i < TASKNUM; i++) { n = (n + 1) % TASKNUM; current = &task[n]; ... 11 8 21
  11. 11. func_t task_main[] = { main1, main2, main3 }; void schedule() { ... for (i = 0; i < TASKNUM; i++) { n = (n + 1) % TASKNUM; current = &task[n]; ... 11 8 21
  12. 12. void task_create() { ... static int n = 0; if (n == TASKNUM) schedule(); ... if (setjmp(task[n].context)) task_start(n); n++; task_create(); 11 8 21
  13. 13. void task_create() { ... static int n = 0; if (n == TASKNUM) schedule(); ... if (setjmp(task[n].context)) task_start(n); n++; task_create(); 11 8 21
  14. 14. 11 8 21
  15. 15. 11 8 21

×