Boost C++ Libraries: Ticket #11457: windows - boost::recursive_mutex leaks event handles when lock contention occurs. https://svn.boost.org/trac10/ticket/11457 <p> When 2+ threads attempt to acquire a recursive_mutex at the same time, an event handle may/will be leaked. </p> <p> This is extremely reproducible in my application. The app runs fine by the way...the leak does not interfere with the expected behavior. It merely leaks handles at a very low rate (&lt; 0.01% of the time the lock is acquired). That rate increases the more threads there are trying to acquire the same locks. </p> <ol><li>Commenting out the call to lock the recursive_mutex eliminates the leak. </li><li>Replacing recursive_mutex with a non-boost lock eliminates the leak. </li><li>Preventing &gt; 1 thread from trying to acquire the recursive_mutex at at time also eliminates the leak. </li><li>The more threads there are fighting over the lock, the more likely it is that handles will be leaked. </li><li>The handle leak is 100% reproducible, but the # of leaks varies with each execution. There is an element of randomness to the quantity of handles leaked. </li></ol><p> Those facts combine to point squarely at lock contention in recursive_mutex as the culprit. </p> <p> I also used the handle.exe utility to confirm that the application was leaking event handles. </p> <p> My application launches 9 threads that each traverse a vector of ~100k objects. Each object owns a recursive_mutex. Each threads acquires &amp; releases each object's lock ~50 times in rapid succession. Each time this complete cycle is run, the application will leak 250-1500 event handles. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11457 Trac 1.4.3 viboes Thu, 20 Aug 2015 23:02:22 GMT status, component changed; owner set https://svn.boost.org/trac10/ticket/11457#comment:1 https://svn.boost.org/trac10/ticket/11457#comment:1 <ul> <li><strong>owner</strong> set 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>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">thread</span> </li> </ul> Ticket viboes Thu, 20 Aug 2015 23:13:27 GMT <link>https://svn.boost.org/trac10/ticket/11457#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11457#comment:2</guid> <description> <p> Please, could you provide a simple example? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Thu, 03 Sep 2015 07:13:51 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11457#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11457#comment:3</guid> <description> <p> I guess that your are on windows. I have no access to windows. </p> <p> Please, could you detail each one of the patches that makes your example to don't leak? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 27 Sep 2015 13:23:42 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11457#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11457#comment:4</guid> <description> <p> Please, give me more details of the point 1. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 11 Oct 2015 19:09:01 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11457#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11457#comment:5</guid> <description> <p> PING !!! </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 10 Nov 2015 17:15:35 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11457#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11457#comment:6</guid> <description> <p> Yes, the handle leak occurs in Windows. I have not experienced it in Linux. Here is a simple example class. </p> <pre class="wiki">class UserInfo { boost::recursive_mutex m_Lock; bool IsEntitled (const unsigned int uBit); } bool CUserInfo::IsEntitled (const unsigned int uBit) { bool bRet = false; boost::recursive_mutex::scoped_lock lock (m_Lock); //do something...anything that takes a few nanoseconds. return bRet; } </pre><p> You can see the leak by creating a simple windows app that launches multiple threads and puts them each in a loop calling <a class="missing wiki">IsEntitled</a>. It will leak event handles for each (or maybe just some?) lock contention events. So the more threads you launch, the more handle leaks you will see. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 12 Nov 2015 03:51:36 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11457#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11457#comment:7</guid> <description> <p> Yes, recursive_mutex leak handles on windows! Please help! </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Thu, 12 Nov 2015 22:24:50 GMT</pubDate> <title>summary changed https://svn.boost.org/trac10/ticket/11457#comment:8 https://svn.boost.org/trac10/ticket/11457#comment:8 <ul> <li><strong>summary</strong> <span class="trac-field-old">boost::recursive_mutex leaks event handles when lock contention occurs.</span> → <span class="trac-field-new">windows - boost::recursive_mutex leaks event handles when lock contention occurs.</span> </li> </ul> <p> I will take a look, but I don't have a Windows platform to check it. </p> <p> Niall, if you have some time, could you take a look at this issue? </p> Ticket anonymous jellyfish Thu, 02 Feb 2017 02:11:33 GMT <link>https://svn.boost.org/trac10/ticket/11457#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11457#comment:9</guid> <description> <p> I saw a rising Event handle count as described because of boost::recursive_mutex contention with many objects. But the handles aren't leaking; if I delete my array of objects, the boost::recursive_mutex destructor releases the Event handle if it created one. </p> <p> So, I don't think there is a bug here. If you have an array of 100k objects each containing boost::recursive_mutex, be prepared for anywhere between 0 and 100k Event handles. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 16 Sep 2017 16:56:04 GMT</pubDate> <title>status changed; resolution set; milestone deleted https://svn.boost.org/trac10/ticket/11457#comment:10 https://svn.boost.org/trac10/ticket/11457#comment:10 <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">worksforme</span> </li> <li><strong>milestone</strong> <span class="trac-field-deleted">To Be Determined</span> </li> </ul> <p> As we don't have an example I propose to close this issue. </p> Ticket viboes Sat, 16 Sep 2017 16:58:48 GMT <link>https://svn.boost.org/trac10/ticket/11457#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11457#comment:11</guid> <description> <p> See <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/13212" title="#13212: Bugs: Windows: condition_variable::notify_one consumes semaphore handles (closed: fixed)">#13212</a> </p> </description> <category>Ticket</category> </item> </channel> </rss>