Boost C++ Libraries: Ticket #11499: windows - exception lock_error while intensive locking/unlocking of shared_mutex on many threads https://svn.boost.org/trac10/ticket/11499 <pre class="wiki">#include "stdafx.h" #include &lt;boost/thread/shared_mutex.hpp&gt; #include &lt;thread&gt; #include &lt;mutex&gt; #include &lt;shared_mutex&gt; #include &lt;atomic&gt; #include &lt;vector&gt; using MutexT = boost::shared_mutex; using ReaderLockT = std::lock_guard&lt;MutexT&gt;; using WriterLockT = std::shared_lock&lt;MutexT&gt;; MutexT gMutex; std::atomic&lt;bool&gt; running = true; long reads = 0; void read() { while (running) { ReaderLockT lock(gMutex); std::this_thread::yield(); ++reads; } } int main() { using namespace std; vector&lt;thread&gt; threads; for (int i = 0; i &lt; 256; ++i) { threads.emplace_back(thread(read)); } string str; getline(std::cin, str); running = false; for (auto&amp; thread : threads) { thread.join(); } return 0; } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11499 Trac 1.4.3 andrew maclean <agm@…> Mon, 27 Jul 2015 21:58:36 GMT version changed https://svn.boost.org/trac10/ticket/11499#comment:1 https://svn.boost.org/trac10/ticket/11499#comment:1 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.57.0</span> → <span class="trac-field-new">Boost 1.58.0</span> </li> </ul> Ticket andrew maclean <agm@…> Mon, 27 Jul 2015 22:50:30 GMT version changed https://svn.boost.org/trac10/ticket/11499#comment:2 https://svn.boost.org/trac10/ticket/11499#comment:2 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.58.0</span> → <span class="trac-field-new">Boost 1.59.0</span> </li> </ul> Ticket andrew maclean <agm@…> Mon, 27 Jul 2015 22:53:47 GMT component changed; owner set https://svn.boost.org/trac10/ticket/11499#comment:3 https://svn.boost.org/trac10/ticket/11499#comment:3 <ul> <li><strong>owner</strong> set to <span class="trac-author">Anthony Williams</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">thread</span> </li> </ul> Ticket andrew maclean <agm@…> Thu, 30 Jul 2015 07:25:25 GMT <link>https://svn.boost.org/trac10/ticket/11499#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11499#comment:4</guid> <description> <p> Replying to <a class="assigned ticket" href="https://svn.boost.org/trac10/ticket/11499" title="#11499: Bugs: windows - exception lock_error while intensive locking/unlocking of ... (assigned)">andrew maclean &lt;agm@…&gt;</a>: </p> <blockquote class="citation"> <pre class="wiki">#include "stdafx.h" #include &lt;boost/thread/shared_mutex.hpp&gt; #include &lt;thread&gt; #include &lt;mutex&gt; #include &lt;shared_mutex&gt; #include &lt;atomic&gt; #include &lt;vector&gt; using MutexT = boost::shared_mutex; using ReaderLockT = std::lock_guard&lt;MutexT&gt;; using WriterLockT = std::shared_lock&lt;MutexT&gt;; MutexT gMutex; std::atomic&lt;bool&gt; running = true; void threadfunc() { while (running) { ReaderLockT lock(gMutex); // exception - eventually... (ymmv) std::this_thread::yield(); } } int main() { using namespace std; vector&lt;thread&gt; threads; for (int i = 0; i &lt; 256; ++i) { threads.emplace_back(thread(threadfunc)); } string str; getline(std::cin, str); running = false; for (auto&amp; thread : threads) { thread.join(); } return 0; } </pre></blockquote> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Wed, 05 Aug 2015 16:48:17 GMT</pubDate> <title>owner, status changed https://svn.boost.org/trac10/ticket/11499#comment:5 https://svn.boost.org/trac10/ticket/11499#comment:5 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Anthony Williams</span> to <span class="trac-author">viboes</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket viboes Wed, 05 Aug 2015 17:26:40 GMT <link>https://svn.boost.org/trac10/ticket/11499#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11499#comment:6</guid> <description> <p> I'm unable to reproduce it on a MAC (I don't have a Windows machine available). Please, could you give more information? </p> </description> <category>Ticket</category> </item> <item> <author>agm@…</author> <pubDate>Wed, 05 Aug 2015 22:35:37 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/11499 https://svn.boost.org/trac10/ticket/11499 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">shared_mutex_exception.png</span> </li> </ul> Ticket viboes Thu, 13 Aug 2015 06:49:02 GMT <link>https://svn.boost.org/trac10/ticket/11499#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11499#comment:7</guid> <description> <p> Where your example is using timed_lock? </p> </description> <category>Ticket</category> </item> <item> <author>andrew maclean <agm@…></author> <pubDate>Thu, 13 Aug 2015 08:03:03 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11499#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11499#comment:8</guid> <description> <p> In shared_mutex.hpp @393 lock() member function </p> <blockquote> <p> void lock() { </p> </blockquote> <p> #if defined BOOST_THREAD_USES_DATETIME </p> <blockquote> <p> BOOST_VERIFY(timed_lock(::boost::detail::get_system_time_sentinel())); </p> </blockquote> <p> #else </p> <blockquote> <p> BOOST_VERIFY(try_lock_until(chrono::steady_clock::now())); </p> </blockquote> <p> #endif </p> <blockquote> <p> } </p> </blockquote> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Thu, 03 Sep 2015 07:06:43 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11499#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11499#comment:9</guid> <description> <p> Please, could you try using a version &gt;= 0 </p> <pre class="wiki">#define BOOST_THREAD_VERSION 4 #include &lt;boost/thread/shared_mutex.hpp&gt; .... </pre><p> If you can not, could you try replacing </p> <pre class="wiki"> #if defined BOOST_THREAD_USES_DATETIME BOOST_VERIFY(timed_lock(::boost::detail::get_system_time_sentinel())); #else BOOST_VERIFY(try_lock_until(chrono::steady_clock::now())); #endif </pre><p> by </p> <pre class="wiki"> BOOST_VERIFY(try_lock_until(chrono::steady_clock::now())); </pre><p> The same for lock_shared. </p> <p> Thanks for your help, Vicente </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Tue, 08 Sep 2015 17:31:33 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11499#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11499#comment:10</guid> <description> <p> <a class="ext-link" href="https://github.com/boostorg/thread/commit/b30cde32d4d90f601acc136bd02a4cdcbf3ea602"><span class="icon">​</span>https://github.com/boostorg/thread/commit/b30cde32d4d90f601acc136bd02a4cdcbf3ea602</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 27 Sep 2015 13:19:58 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11499#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11499#comment:11</guid> <description> <p> It seems this change doesn't works at all. I've rolled back the change. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 06 Dec 2015 09:20:08 GMT</pubDate> <title>summary changed https://svn.boost.org/trac10/ticket/11499#comment:12 https://svn.boost.org/trac10/ticket/11499#comment:12 <ul> <li><strong>summary</strong> <span class="trac-field-old">exception lock_error while intensive locking/unlocking of shared_mutex on many threads</span> → <span class="trac-field-new">windows - exception lock_error while intensive locking/unlocking of shared_mutex on many threads</span> </li> </ul> Ticket viboes Mon, 15 Aug 2016 17:59:25 GMT <link>https://svn.boost.org/trac10/ticket/11499#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11499#comment:13</guid> <description> <p> You can define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN to get the generic implementation. It is slower but IMHO it has less bugs. </p> <p> See <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/12386" title="#12386: Bugs: lock_error exception when using try_lock_for() on Windows (closed: duplicate)">#12386</a> </p> </description> <category>Ticket</category> </item> </channel> </rss>