Boost C++ Libraries: Ticket #7720: exception lock_error while intensive locking/unlocking of mutex https://svn.boost.org/trac10/ticket/7720 <p> Hi, Anthony and Vicente. </p> <pre class="wiki">//////////////////////////////////////////// #include &lt;boost/thread/thread.hpp&gt; using namespace boost; shared_mutex mtx; void f() { while (true) { upgrade_lock&lt;shared_mutex&gt; lock(mtx); } } void g() { while (true) { shared_lock&lt;shared_mutex&gt; lock(mtx); } } void h() { while (true) { unique_lock&lt;shared_mutex&gt; lock(mtx); } } int main() { thread t0(f); thread t1(g); thread t2(h); t0.join(); t1.join(); t2.join(); return 0; } //////////////////////////////////////////// </pre><p> I ran this program and got exception boost::lock_error in some minutes. </p> <p> Used MS VS 2005 Version 8.0.50727.867, Boost C++ Libraries 1.51 and MS Windows 7 Pro version 6.1.7601 SP1. </p> <p> Regards, Sergey. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7720 Trac 1.4.3 viboes Fri, 23 Nov 2012 06:36:00 GMT owner, status, description changed https://svn.boost.org/trac10/ticket/7720#comment:1 https://svn.boost.org/trac10/ticket/7720#comment:1 <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> <li><strong>description</strong> modified (<a href="/trac10/ticket/7720?action=diff&amp;version=1">diff</a>) </li> </ul> <p> Please, could you try defining BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN to see if the error persist on the generic implementation? </p> Ticket sergey.stepanov@… Fri, 23 Nov 2012 11:08:57 GMT <link>https://svn.boost.org/trac10/ticket/7720#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7720#comment:2</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7720#comment:1" title="Comment 1">viboes</a>: With this macro it works fine. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 25 Nov 2012 08:18:14 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7720#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7720#comment:3</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7720#comment:2" title="Comment 2">sergey.stepanov@…</a>: </p> <blockquote class="citation"> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7720#comment:1" title="Comment 1">viboes</a>: With this macro it works fine. </p> </blockquote> <p> The specific implementation on Windows had some bugs that were fixed by the generic implementation. This is why I have added this macro. It will be defined by default since 1.53. Could we close this ticket? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 26 Nov 2012 07:45:06 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7720#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7720#comment:4</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7720#comment:3" title="Comment 3">viboes</a>: </p> <blockquote class="citation"> <p> The specific implementation on Windows had some bugs that were fixed by the generic implementation. This is why I have added this macro. It will be defined by default since 1.53. Could we close this ticket? </p> </blockquote> <p> I think we could. Thank you for your help. Sergey. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Mon, 26 Nov 2012 23:11:51 GMT</pubDate> <title>status changed; resolution set; milestone deleted https://svn.boost.org/trac10/ticket/7720#comment:5 https://svn.boost.org/trac10/ticket/7720#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> <li><strong>milestone</strong> <span class="trac-field-deleted">To Be Determined</span> </li> </ul> Ticket viboes Sat, 19 Jan 2013 10:43:09 GMT status changed; milestone set; resolution deleted https://svn.boost.org/trac10/ticket/7720#comment:6 https://svn.boost.org/trac10/ticket/7720#comment:6 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">wontfix</span> </li> <li><strong>milestone</strong> → <span class="trac-field-new">To Be Determined</span> </li> </ul> <p> Reopened as BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN will not be defined by default and as <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7906" title="#7906: Bugs: Very bad performance of generic implementation of shared_mutex on windows (closed: wontfix)">#7906</a> states there is a lost in performances when this define is defined. </p> Ticket Andrey <nikolay@…> Tue, 12 Feb 2013 05:05:55 GMT <link>https://svn.boost.org/trac10/ticket/7720#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7720#comment:7</guid> <description> <p> Ooops, the same issue in my second project already. boost 1.52. Any plans when fix for upgrade_lock will be available? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Tue, 12 Feb 2013 06:25:05 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7720#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7720#comment:8</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7720#comment:7" title="Comment 7">Andrey &lt;nikolay@…&gt;</a>: </p> <blockquote class="citation"> <p> Ooops, the same issue in my second project already. boost 1.52. Any plans when fix for upgrade_lock will be available? </p> </blockquote> <p> No. For the time been I have no idea how to fix it. </p> <p> Until the share_mutex errors have been fixed, please define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN. Even if it takes more time it works correctly (well better). </p> </description> <category>Ticket</category> </item> <item> <author>Andrey <nikolay@…></author> <pubDate>Tue, 12 Feb 2013 06:53:13 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7720#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7720#comment:9</guid> <description> <p> Unfortunately, my first project where the problem is reproducible is really time critical module. It is a reason why the performance issue with generic implementation has been found in such little time period. I have made some tests on 1.52 and found that from the performance perspective it is better for me don't use upgrade_lock at all than use generic implementation of shared_mutex. Now while new release of my program is under development I am waiting for the fix for this issue. But if it will not be fixed till end of March I will need to choose: </p> <ul><li>downgrade boost to 1.44 to have fast and bug-free upgrade_lock with shared_mutex </li></ul><p> or </p> <ul><li>rewrite code to don't use upgrade_lock in my projects </li></ul> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Wed, 13 Feb 2013 07:19:49 GMT</pubDate> <title>severity changed https://svn.boost.org/trac10/ticket/7720#comment:10 https://svn.boost.org/trac10/ticket/7720#comment:10 <ul> <li><strong>severity</strong> <span class="trac-field-old">Problem</span> → <span class="trac-field-new">Regression</span> </li> </ul> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7720#comment:9" title="Comment 9">Andrey &lt;nikolay@…&gt;</a>: </p> <blockquote class="citation"> <p> Unfortunately, my first project where the problem is reproducible is really time critical module. It is a reason why the performance issue with generic implementation has been found in such little time period. I have made some tests on 1.52 and found that from the performance perspective it is better for me don't use upgrade_lock at all than use generic implementation of shared_mutex. Now while new release of my program is under development I am waiting for the fix for this issue. But if it will not be fixed till end of March I will need to choose: </p> <ul><li>downgrade boost to 1.44 to have fast and bug-free upgrade_lock with shared_mutex </li></ul></blockquote> <p> This is an interesting information. BTW, have you tried 1.45? Do you know the first version which introduced the regression? </p> <blockquote class="citation"> <p> or </p> <ul><li>rewrite code to don't use upgrade_lock in my projects </li></ul></blockquote> <p> I can not ensure you when this will be fixed but the fact this is a regression would surely help. </p> Ticket Andrey <nikolay@…> Wed, 13 Feb 2013 08:44:53 GMT <link>https://svn.boost.org/trac10/ticket/7720#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7720#comment:11</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7720#comment:10" title="Comment 10">viboes</a>: </p> <blockquote class="citation"> <p> This is an interesting information. BTW, have you tried 1.45? Do you know the first version which introduced the regression? </p> </blockquote> <p> I haven't tried versions 1.45-1.51. The previous boost version I used is 1.44. May be author of this ticket knows first boost version affected. </p> </description> <category>Ticket</category> </item> <item> <author>sergey.stepanov@…</author> <pubDate>Wed, 13 Feb 2013 09:07:02 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7720#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7720#comment:12</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7720#comment:11" title="Comment 11">Andrey &lt;nikolay@…&gt;</a>: </p> <blockquote class="citation"> <p> I haven't tried versions 1.45-1.51. The previous boost version I used is 1.44. May be author of this ticket knows first boost version affected. </p> </blockquote> <p> First time I encountered this problem is version 1.51. Previous was 1.45. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Wed, 13 Feb 2013 11:59:13 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7720#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7720#comment:13</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7720#comment:12" title="Comment 12">sergey.stepanov@…</a>: </p> <blockquote class="citation"> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7720#comment:11" title="Comment 11">Andrey &lt;nikolay@…&gt;</a>: </p> <blockquote class="citation"> <p> I haven't tried versions 1.45-1.51. The previous boost version I used is 1.44. May be author of this ticket knows first boost version affected. </p> </blockquote> <p> First time I encountered this problem is version 1.51. Previous was 1.45. </p> </blockquote> <p> Do you mean that 1.45 works? If the answer is yes, I should be the responsable of the regression :( </p> <p> I will take a deeper look. </p> </description> <category>Ticket</category> </item> <item> <author>sergey.stepanov@…</author> <pubDate>Wed, 13 Feb 2013 12:12:27 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7720#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7720#comment:14</guid> <description> <blockquote class="citation"> <p> Do you mean that 1.45 works? </p> </blockquote> <p> I'm not sure. But it is not difficult to verify. Just run my example and wait a few minutes. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 16 Feb 2013 17:29:37 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7720#comment:15 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7720#comment:15</guid> <description> <p> Hi, </p> <p> I didn't had access to a windows machine during the week. I have tested it now I confirm the error. </p> <p> The following patch works for me. Could you check it? </p> <pre class="wiki">svn diff boost/thread/win32/shared_mutex.hpp Index: boost/thread/win32/shared_mutex.hpp =================================================================== --- boost/thread/win32/shared_mutex.hpp (revision 82919) +++ boost/thread/win32/shared_mutex.hpp (working copy) @@ -737,7 +737,7 @@ { release_waiters(old_state); } else { - release_waiters(old_state); + //release_waiters(old_state); } break; } </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 16 Feb 2013 23:24:25 GMT</pubDate> <title>milestone changed https://svn.boost.org/trac10/ticket/7720#comment:16 https://svn.boost.org/trac10/ticket/7720#comment:16 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.54.0</span> </li> </ul> Ticket sergey.stepanov@… Mon, 18 Feb 2013 08:08:21 GMT <link>https://svn.boost.org/trac10/ticket/7720#comment:17 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7720#comment:17</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7720#comment:16" title="Comment 16">viboes</a>: With this correction there are no exceptions. Used: boost ver. 1.51, MS VS 2005, MS Windows 7 Pro SP1. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Mon, 18 Feb 2013 12:12:04 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7720#comment:18 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7720#comment:18</guid> <description> <p> Committed in trunk revision <a class="changeset" href="https://svn.boost.org/trac10/changeset/82973" title="Thread: commit proposed patch for #7720.">[82973]</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 23 Mar 2013 02:11:23 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/7720#comment:19 https://svn.boost.org/trac10/ticket/7720#comment:19 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Committed revision <a class="changeset" href="https://svn.boost.org/trac10/changeset/83525" title="Thread: merge from trunk. 1.54">[83525]</a>. </p> Ticket ajay.sonawane@… Wed, 05 Nov 2014 05:23:18 GMT <link>https://svn.boost.org/trac10/ticket/7720#comment:20 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7720#comment:20</guid> <description> <p> I modified the test program slightly and I got the lock_Error exceptions again. I'm using boost 1.54.0. Please let me know if the fix for this problem is available. </p> <p> shared_mutex mtx; </p> <p> unsigned int sharedVariable = 0; </p> <p> void upgrade() { </p> <blockquote> <p> while (true) { </p> <blockquote> <p> try { </p> <blockquote> <p> upgrade_lock&lt;shared_mutex&gt; lock(mtx); std::cout &lt;&lt; sharedVariable; </p> </blockquote> <p> } catch(boost::lock_error&amp; err) { </p> <blockquote> <p> std::cout &lt;&lt; "Exception in Upgrade: " &lt;&lt; err.what() &lt;&lt; std::endl; </p> </blockquote> <p> } </p> </blockquote> <p> } </p> </blockquote> <p> } </p> <p> void shared() { </p> <blockquote> <p> while (true) { </p> <blockquote> <p> try { </p> <blockquote> <p> shared_lock&lt;shared_mutex&gt; lock(mtx); std::cout &lt;&lt; sharedVariable; </p> </blockquote> <p> } catch(boost::lock_error&amp; err) { </p> <blockquote> <p> std::cout &lt;&lt; "Exception in Shared: " &lt;&lt; err.what() &lt;&lt; std::endl; </p> </blockquote> <p> } </p> </blockquote> <p> } </p> </blockquote> <p> } </p> <p> void unique() { </p> <blockquote> <p> while (true) { </p> <blockquote> <p> try { </p> <blockquote> <p> unique_lock&lt;shared_mutex&gt; lock(mtx); ++sharedVariable;; </p> </blockquote> <p> } catch(boost::lock_error&amp; err) { </p> <blockquote> <p> std::cout &lt;&lt; "Exception in Unique: " &lt;&lt; err.what() &lt;&lt; std::endl; </p> </blockquote> <p> } </p> </blockquote> <p> } </p> </blockquote> <p> } </p> <p> int main() { </p> <blockquote> <p> unsigned int numThreads = 1000; </p> </blockquote> <p> </p> <blockquote> <p> boost::thread_group grp; { </p> <blockquote> <p> for (unsigned int i = 0; i &lt; numThreads; i++) { </p> <blockquote> <p> if(i % 5 == 0) </p> <blockquote> <p> grp.create_thread (boost::bind (&amp;unique)); </p> </blockquote> <p> else if(i%3 == 0) </p> <blockquote> <p> grp.create_thread (boost::bind (&amp;upgrade)); </p> </blockquote> <p> else </p> <blockquote> <p> grp.create_thread (boost::bind (&amp;shared)); </p> </blockquote> </blockquote> <p> } </p> </blockquote> <p> } </p> </blockquote> <blockquote> <p> grp.join_all (); </p> </blockquote> <blockquote> <p> return 0; </p> </blockquote> <p> } </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Wed, 05 Nov 2014 06:44:36 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7720#comment:21 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7720#comment:21</guid> <description> <p> Sorry for not updating the ticket. This has been fixed as </p> <pre class="wiki"> void release_shared_waiters(state_data old_state) { if(old_state.shared_waiting || old_state.exclusive_waiting) { BOOST_VERIFY(detail::win32::ReleaseSemaphore(semaphores[unlock_sem],old_state.shared_waiting + (old_state.exclusive_waiting?1:0),0)!=0); } } ... if(last_reader) { release_waiters(old_state); } else { release_shared_waiters(old_state); } </pre><p> Please, could you try it? </p> </description> <category>Ticket</category> </item> <item> <author>ajay.sonawane@…</author> <pubDate>Wed, 05 Nov 2014 07:35:42 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7720#comment:22 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7720#comment:22</guid> <description> <p> Which is the boost version in which it is fixed ? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Wed, 05 Nov 2014 18:30:13 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7720#comment:23 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7720#comment:23</guid> <description> <p> It was included with <a class="ext-link" href="https://github.com/boostorg/thread/commit/6f91af2154da808eb29de2e9e12c3e1774cdea31"><span class="icon">​</span>https://github.com/boostorg/thread/commit/6f91af2154da808eb29de2e9e12c3e1774cdea31</a> </p> <p> Try to address <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/9569" title="#9569: Bugs: [windows] Upgrade lock is not acquired when previous upgrade lock ... (closed: fixed)">#9569</a>. 5 Oct </p> <p> This has been delivered with Boost 1.57. </p> </description> <category>Ticket</category> </item> <item> <author>ajay.sonawane@…</author> <pubDate>Thu, 06 Nov 2014 04:22:22 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7720#comment:24 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7720#comment:24</guid> <description> <p> I did same changed in boost/thread/win32/shared_mutex.hpp from boost 1.54.0 and compiled my program. I presume I do not need to make recompile boost library. After the above changes you mentioned, I'm still getting boost::lock_error - Operation completed successfully. I guess I may need to download boost 1.57 to verify this issue. </p> </description> <category>Ticket</category> </item> <item> <author>m@…</author> <pubDate>Wed, 25 Mar 2015 01:08:43 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7720#comment:25 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7720#comment:25</guid> <description> <p> I am seeing this error on boost 1.57. It occurs with heavy mixed use of <code>shared_lock</code>, <code>upgrade_lock</code>, and <code>upgrade_to_unique_lock</code> on a <code>shared_mutex</code>. My project is on Windows 64-bit. </p> </description> <category>Ticket</category> </item> <item> <author>duchungjava@…</author> <pubDate>Thu, 17 Sep 2015 08:00:41 GMT</pubDate> <title>status changed; resolution deleted https://svn.boost.org/trac10/ticket/7720#comment:26 https://svn.boost.org/trac10/ticket/7720#comment:26 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> <p> To whom it may concern, </p> <p> On Boost 1.57, I can replicate this problem with the following code: </p> <div class="wiki-code"><div class="code"><pre><span class="n">boost</span><span class="o">::</span><span class="n">shared_mutex</span> <span class="n">mutex</span><span class="p">;</span> <span class="kt">void</span> <span class="nf">shared_proc</span><span class="p">()</span> <span class="p">{</span> <span class="k">while</span> <span class="p">(</span> <span class="mi">1</span> <span class="p">)</span> <span class="p">{</span> <span class="n">boost</span><span class="o">::</span><span class="n">shared_lock</span><span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">shared_mutex</span><span class="o">&gt;</span> <span class="n">lock</span><span class="p">(</span><span class="n">mutex</span><span class="p">);</span> <span class="n">boost</span><span class="o">::</span><span class="n">this_thread</span><span class="o">::</span><span class="n">sleep_for</span><span class="p">(</span><span class="n">boost</span><span class="o">::</span><span class="n">chrono</span><span class="o">::</span><span class="n">seconds</span><span class="p">(</span><span class="mi">2</span><span class="p">));</span> <span class="p">}</span> <span class="p">}</span> <span class="kt">void</span> <span class="nf">upgrade_proc</span><span class="p">()</span> <span class="p">{</span> <span class="k">while</span> <span class="p">(</span> <span class="mi">1</span> <span class="p">)</span> <span class="p">{</span> <span class="n">boost</span><span class="o">::</span><span class="n">upgrade_lock</span><span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">shared_mutex</span><span class="o">&gt;</span> <span class="n">lock</span><span class="p">(</span><span class="n">mutex</span><span class="p">);</span> <span class="n">boost</span><span class="o">::</span><span class="n">this_thread</span><span class="o">::</span><span class="n">sleep_for</span><span class="p">(</span><span class="n">boost</span><span class="o">::</span><span class="n">chrono</span><span class="o">::</span><span class="n">milliseconds</span><span class="p">(</span><span class="mi">1</span><span class="p">));</span> <span class="p">}</span> <span class="p">}</span> <span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span> <span class="n">boost</span><span class="o">::</span><span class="kr">thread</span> <span class="n">ts</span><span class="p">(</span><span class="n">boost</span><span class="o">::</span><span class="n">bind</span><span class="p">(</span><span class="n">shared_proc</span><span class="p">));</span> <span class="n">boost</span><span class="o">::</span><span class="kr">thread</span> <span class="n">t1</span><span class="p">(</span><span class="n">boost</span><span class="o">::</span><span class="n">bind</span><span class="p">(</span><span class="n">upgrade_proc</span><span class="p">));</span> <span class="n">boost</span><span class="o">::</span><span class="kr">thread</span> <span class="n">t2</span><span class="p">(</span><span class="n">boost</span><span class="o">::</span><span class="n">bind</span><span class="p">(</span><span class="n">upgrade_proc</span><span class="p">));</span> <span class="n">ts</span><span class="p">.</span><span class="n">join</span><span class="p">();</span> <span class="n">t1</span><span class="p">.</span><span class="n">join</span><span class="p">();</span> <span class="n">t2</span><span class="p">.</span><span class="n">join</span><span class="p">();</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> <span class="p">}</span> </pre></div></div><p> By testing this code with different Boost versions, I've confirmed that: </p> <ol><li>Boost 1.56 doesn't throw exception </li><li>Boost 1.57 and 1.59 throw exception instantly </li></ol><p> I think the root reason is: The variable state.shared_count in shared_mutex.hpp couldn't be decreased/reset properly when a shared_mutex is being used for both shared_lock and upgrade_lock. </p> <p> (I'm using Visual Studio 2012 in this test case) </p> <p> Yours sincerely, Hung Mai </p> Ticket anonymous Thu, 17 Sep 2015 08:15:11 GMT <link>https://svn.boost.org/trac10/ticket/7720#comment:27 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7720#comment:27</guid> <description> <p> I'm sorry that I made a mistake in the previous post. </p> <p> This is the updated conclusion: "I think the variable state.shared_waiting in shared_mutex.hpp couldn't be decreased/reset properly when a shared_mutex is being used for both shared_lock and upgrade_lock" </p> <p> Thank you, </p> <p> Hung Mai </p> </description> <category>Ticket</category> </item> <item> <author>duchungjava@…</author> <pubDate>Thu, 17 Sep 2015 08:50:56 GMT</pubDate> <title>version, milestone changed https://svn.boost.org/trac10/ticket/7720#comment:28 https://svn.boost.org/trac10/ticket/7720#comment:28 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.51.0</span> → <span class="trac-field-new">Boost 1.59.0</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.54.0</span> → <span class="trac-field-new">To Be Determined</span> </li> </ul> Ticket viboes Thu, 17 Sep 2015 17:53:24 GMT <link>https://svn.boost.org/trac10/ticket/7720#comment:29 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7720#comment:29</guid> <description> <p> I'm a little bit busy for two weeks. </p> <p> For those that can not wait until we have a fix, </p> <p> you could you define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN. It seems that this works well even if it performs worst. </p> </description> <category>Ticket</category> </item> <item> <author>duchungjava@…</author> <pubDate>Fri, 18 Sep 2015 10:19:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7720#comment:30 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7720#comment:30</guid> <description> <p> Thank you Viboes, </p> <p> Yes, it's true that BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN works well in all of my test cases. However, due to the performance issue, it's a difficult decision for us to apply it to our system. </p> <p> In one of my experiments, on Boost 1.59, if I modify the unlock_upgrade() to reset "new_state.shared_waiting" to zero regardless what the status of "last_reader" is, everything seems to work properly. </p> <p> I hope you will consider this experiment when you have time. </p> <p> Best regards, Hung Mai </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Fri, 18 Sep 2015 21:37:39 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7720#comment:31 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7720#comment:31</guid> <description> <p> Please, be free to provide a patch. If it works for you I will commit it. </p> </description> <category>Ticket</category> </item> <item> <author>Hung Mai <duchungjava@…></author> <pubDate>Mon, 21 Sep 2015 08:42:50 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/7720 https://svn.boost.org/trac10/ticket/7720 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">shared_mutex.hpp</span> </li> </ul> <p> Starting from 1.57, unlock_upgrade() should always reset the variable "new_state.shared_waiting" </p> Ticket Hung Mai <duchungjava@…> Mon, 21 Sep 2015 08:57:29 GMT <link>https://svn.boost.org/trac10/ticket/7720#comment:32 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7720#comment:32</guid> <description> <p> Hi Viboes, </p> <p> Since I don't know how to provide the patch in the desired format, I've attached the file with the changes I made based on Boost-1.59 </p> <p> Basically, there is just one small change in the unlock_upgrade function as following: </p> <div class="wiki-code"><div class="code"><pre><span class="kt">void</span> <span class="nf">unlock_upgrade</span><span class="p">()</span> <span class="p">{</span> <span class="c1">// ...</span> <span class="n">new_state</span><span class="p">.</span><span class="n">shared_waiting</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span> <span class="c1">// adds this line</span> <span class="k">if</span><span class="p">(</span><span class="n">last_reader</span><span class="p">)</span> <span class="p">{</span> <span class="k">if</span><span class="p">(</span><span class="n">new_state</span><span class="p">.</span><span class="n">exclusive_waiting</span><span class="p">)</span> <span class="p">{</span> <span class="o">--</span><span class="n">new_state</span><span class="p">.</span><span class="n">exclusive_waiting</span><span class="p">;</span> <span class="n">new_state</span><span class="p">.</span><span class="n">exclusive_waiting_blocked</span><span class="o">=</span><span class="nb">false</span><span class="p">;</span> <span class="p">}</span> <span class="c1">// new_state.shared_waiting=0; // comment out this line</span> <span class="p">}</span> <span class="c1">// ...</span> <span class="p">}</span> </pre></div></div><p> Thank you, </p> <p> Hung Mai </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Wed, 23 Sep 2015 22:09:24 GMT</pubDate> <title>version, milestone changed https://svn.boost.org/trac10/ticket/7720#comment:33 https://svn.boost.org/trac10/ticket/7720#comment:33 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.59.0</span> → <span class="trac-field-new">Boost 1.51.0</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.60.0</span> </li> </ul> <p> I have committed your patch </p> <p> <a class="ext-link" href="https://github.com/boostorg/thread/commit/205a1d7e2b7ca12058ea94fb147d27cdaad2753a"><span class="icon">​</span>https://github.com/boostorg/thread/commit/205a1d7e2b7ca12058ea94fb147d27cdaad2753a</a> </p> <p> I will check if there are no regressions on the Boost testers. </p> <p> Thanks for identifying this. </p> Ticket Hung Mai <duchungjava@…> Thu, 24 Sep 2015 01:55:00 GMT <link>https://svn.boost.org/trac10/ticket/7720#comment:34 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7720#comment:34</guid> <description> <p> Thank you Viboes, </p> <p> It's my pleasure to contribute to the community. <br /> I hope everything will go smoothly. </p> <p> Best regards, </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 27 Sep 2015 13:40:56 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/7720#comment:35 https://svn.boost.org/trac10/ticket/7720#comment:35 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <blockquote> <p> <a class="ext-link" href="https://github.com/boostorg/thread/commit/730cb550e6d969520c3f39e0ddf5d80351bddf3a"><span class="icon">​</span>https://github.com/boostorg/thread/commit/730cb550e6d969520c3f39e0ddf5d80351bddf3a</a> </p> </blockquote> Ticket anonymous Thu, 28 Jul 2016 11:44:49 GMT <link>https://svn.boost.org/trac10/ticket/7720#comment:36 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7720#comment:36</guid> <description> <p> Hi, </p> <p> I'm hitting this bug, and I'm stuck with Boost 1.55 for the time being. Is there a workaround that doesn't require modifying Boost's source code? Some posts of this thread mention BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN: how bad is the performance loss? </p> <p> Thanks for your help. </p> <p> Franz </p> </description> <category>Ticket</category> </item> </channel> </rss>