0x20; printf("before: n is 0x%x\n", n); asm volatile("push $0x10;\n\t" "pop % [output];\n\t" :[output] "=g"(n)); printf("after: n is 0x%x\n", n); } $ ./a.out before: n is 0x20 after: n is 0x10
important. It switches not only IOPL between tasks, 46 * it also protects other tasks from NT leaking through sysenter etc. 47 */ 48#define switch_to(prev, next, last) \ このマクロはカレントプロセスの eip 、 esp 、 ebp の保存と、 次のプロセスのために eip 、 esp 、 ebp の設定、 __switch_to() の呼出をします。 __switch_to() から戻った時点で、プロセスが 切り替わっています。
= t; printf("switch id %d to %d\n", cur->thread_id, t->thread_id); _ContextSwitch(cur->context, t->context); } else if (currentThread->thread_id == MAIN_THREAD_ID) { // main thread's state is FINISH. printf("There is only main thread\n"); } else { printf("There is no active thread\n"); } }
a new thread (i=2) [id=2] switch id 0 to 2 thread(2): 0. switch id 2 to 1 thread(1): 0. switch id 1 to 2 ~ switch id 1 to 2 thread (i=2) finished. switch id -1 to 1 thread (i=1) finished. switch id -1 to 0 main thread finished.