BruCe 发表于 2019-7-6 18:40:08

为什么《石器时代》使用信号量?

C++11 和 Boost.Thread 都没有提供信号量。对此 Boost 是这样解释的:

Semaphore was removed as too error prone. The same effect can be achieved with greater safety by the combination of a mutex and a condition variable. Dijkstra (the semaphore's inventor), Hoare, and Brinch Hansen all depreciated semaphores and advocated more structured alternatives. In a 1969 letter to Brinch Hansen, Wirth said "semaphores ... are not suitable for higher level languages." summarizes typical errors as "omitting a P or a V, or accidentally coding a P on one semaphore and a V on on another", forgetting to include all references to shared objects in critical sections, and confusion caused by using the same primitive for "both condition synchronization and mutual exclusion".

Elvui 发表于 2020-2-18 20:10:51

学习了 学习了:lol:lol
页: [1]
查看完整版本: 为什么《石器时代》使用信号量?