我想使用Boost的upgrade_lock
(使用this example,但我碰上一个饥饿的问题。其实我用从this post代码饥饿与upgrade_lock
,但我想一个跟上时代的讨论。我在WorkerKiller后运行400个线程。我遇到相同问题的anoneironaut,在mentionned帖子的作者。
我已经看到霍华德Hinnant(欣南特)的命题,但我真的不希望包括m矿石外部代码(此外,我无法让他编译到现在为止),并在6个月后发布的评论声明“Boost现在使用公平实现”(12年3月12日)。
Note the the lack of reader-writer priority policies in shared_mutex. This is
due to an algorithm credited to Alexander Terekhov which lets the OS decide
which thread is the next to get the lock without caring whether a unique lock or
shared lock is being sought. This results in a complete lack of reader or writer
starvation. It is simply fair.".
,并存入亚历山大捷列霍夫的算法是霍华德Hinnant(欣南特)会谈,所以我期望的1.55提升执行的行为像霍华德Hinnant(欣南特)的一答案,事实并非如此。它的行为与问题完全相同。
为什么我的WorkerKiller患有饥饿?
更新:将其用this code观察:
- 的Debian 64,升压1.55(二者Debian版和一个从来源汇编),与两个铛++和g ++
- Ubuntu的64位, Boost 1.54,同时有铿锵++(3.4-1ubuntu1)和g ++(4.8.1-10ubuntu9)
你运行的是什么编译器和平台?我无法在VC11 x64版本上重现Boost 1.55的问题。 – ComicSansMS
这很有趣。我复制了我的代码[在这里](https://gist.github.com/anonymous/bd3440d438da82061f22)。它在Debian(boost 1.55)和Ubuntu(boost 1.54)上使用clang ++和g ++进行了测试。 – JonesV
现在明白了,我并没有意识到你正在使用'upgrade_lock'而不是普通的独占锁。 – ComicSansMS