https://jyywiki.cn/OS/2023/build/lect6.ipynb
人类是 sequential creature
人类是 (不轻言放弃的) sequential creature
插入 “神秘代码”,使得所有其他 “神秘代码” 都不能并发
void Tsum() {
stop_the_world();
// 临界区 critical section
sum++;
resume_the_world();
}
Stop the world 真的是可能的
int locked = UNLOCK;
void critical_section() {
retry:
if (locked != UNLOCK) {
goto retry;
}
locked = LOCK;
// critical section
locked = UNLOCK;
}