Dekker 与 Peterson 的早期算法
原片 00:39:07—00:41:59

lock、unlock,也就是 acquire、release,怎样实现?这张图上次见过。1965 年,有了第一个公开的正确算法。它说 process P 能 enter critical section,if the other does not want to enter;否则 it may enter only if it is its turn。听起来像绕口令。那时用 process,thread 还没在操作系统中出现,就像今天说的每个进程在内核中执行的共享内存线程,是进程的一部分。链接中详细解释了 Dekker 算法,阅读材料有趣,开头就展示协议所有可能状态的图。教科书一般也会介绍那段看起来奇怪的代码。

这里不详细讲状态空间。人们花很长时间想出各种算法,到 1981 年才有一个比较令人满意的方案,描述却仍像绕口令:process p can enter the critical section,if the other does not,即别人不想进;或者 it has indicated its desire,自己已表示想进。

接着还要 and has given the other process the turn,仍让人费解。这里给出的代码与经典教科书一样。先忽略右边的 barrier,A 这个 thread、进程先 a 等于 1,再 turn 等于 b。

随后等待:not b 就 break,可以进入;turn 不等于 b 也能进入 critical section。退出时令 a 等于 0。接下来演示,让大家看看当时怎样解决并发问题。
