玩具的意义
玩具实现了最重要的机制
- 状态机管理、系统调用、上下文切换
- 许多更复杂的机制只是 “更多的代码”
我们甚至没有脱离真实的操作系统
void sys_write(const char *s) { printf("%s", s); }
int sys_read() { return rand() % 2; }
void sys_spawn(void *(*fn)(void *), void *args) {
pthread_create(&procs[n++], NULL, fn, args);
}