我正在尝试使用Boost的
实际上,我正在使用此帖子中的代码,但我想要一个最新的讨论。在WorkerKiller之后,我运行了400个线程。我遇到了与提到的帖子的作者anoneironaut完全相同的问题。
我看到了来自Howard Hinnant的建议,但我不想包含更多外部代码(而且我现在无法编译他的代码),并且6个月后发布的评论指出“Boost现在使用公平的实现”(2012年12月3日)。 Boost 1.55文档指出:
算法归功于Alexander Terekhov,这是Howard Hinnant所谈论的算法,因此我期望1.55倍的提升实现的行为就像Howard Hinnant的答案一样,但事实并非如此。它的行为与问题完全相同。
为什么我的WorkerKiller会遭受饥饿?
更新:在以下环境中使用this code观察到:
Debian x64,Boost 1.55(Debian版本和从源代码编译的版本),使用clang++和g++
Ubuntu x64,Boost 1.54,使用clang++(3.4-1ubuntu1)和g++(4.8.1-10ubuntu9)
upgrade_lock
(使用此示例),但我遇到了饥饿问题。实际上,我正在使用此帖子中的代码,但我想要一个最新的讨论。在WorkerKiller之后,我运行了400个线程。我遇到了与提到的帖子的作者anoneironaut完全相同的问题。
我看到了来自Howard Hinnant的建议,但我不想包含更多外部代码(而且我现在无法编译他的代码),并且6个月后发布的评论指出“Boost现在使用公平的实现”(2012年12月3日)。 Boost 1.55文档指出:
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.".
算法归功于Alexander Terekhov,这是Howard Hinnant所谈论的算法,因此我期望1.55倍的提升实现的行为就像Howard Hinnant的答案一样,但事实并非如此。它的行为与问题完全相同。
为什么我的WorkerKiller会遭受饥饿?
更新:在以下环境中使用this code观察到:
Debian x64,Boost 1.55(Debian版本和从源代码编译的版本),使用clang++和g++
Ubuntu x64,Boost 1.54,使用clang++(3.4-1ubuntu1)和g++(4.8.1-10ubuntu9)
upgrade_lock
而不是普通的独占锁。 - ComicSansMS