Boost C++ Libraries: Ticket #6108: Boost interprocess lock consumes 100% CPU on OS X https://svn.boost.org/trac10/ticket/6108 <p> I have some code which waits for write operation on Shared Memory. If no one writes it continues to wait. </p> <pre class="wiki"> Test* Foo::Get() { boost::interprocess::scoped_lock&lt;boost::interprocess::interprocess_mutex&gt; lock ( mutex ) ; // mutex is boost::interprocess::interprocess_mutex if ( this-&gt;check == 0 ) this-&gt;interprocessCondition.wait ( lock ) ; // interprocessCondition is boost::interprocess::interprocess_condition ... } </pre><p> CPU consumption is 100%. </p> <p> Debugging leads to inline void sched_yield(), for windows it calls Sleep(1) but I cannot find any definition for Mac. </p> <p> I believe we need sched_yield() implementation and may be usleep(1000) within it. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6108 Trac 1.4.3 Ion Gaztañaga Fri, 23 Dec 2011 12:53:03 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/6108#comment:1 https://svn.boost.org/trac10/ticket/6108#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> OS X is unix-like and calls POSIX function sched_yield(). CPU consumption is high if there are no other threads in the system (this is the best we can do). I don't think this is a bug, as sleeping for some time will hurt performance of other implementations with short lock times. </p> Ticket dummymail000@… Sat, 05 Jan 2013 05:34:56 GMT <link>https://svn.boost.org/trac10/ticket/6108#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6108#comment:2</guid> <description> <p> I'm affected by this too. I didn't noted this when starting development. It consumes all the CPU. I'm building a kind of server through shared memory, and the server needs to keep waiting for a message indefinitely. It waits on a condition variable, but then, I noted my fans running high. Can't deploy this thing. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>bledo</dc:creator> <pubDate>Wed, 23 Jan 2013 21:38:01 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6108#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6108#comment:3</guid> <description> <p> (best we can do?) while I agree that sleeping will kill performance, running at 100% CPU will kill battery life on any laptop. Been locking one of the most basic functions, I can't believe you don't think this is a bug. I hope you reconsider. For the moment, boost is a no-no for macOs. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 25 Jul 2013 13:42:51 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6108#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6108#comment:4</guid> <description> <p> +1 buggy. </p> </description> <category>Ticket</category> </item> <item> <author>samuel@…</author> <pubDate>Thu, 25 Jul 2013 13:50:49 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6108#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6108#comment:5</guid> <description> <p> On 10.8, simply adding: </p> <blockquote> <p> #define BOOST_INTERPROCESS_POSIX_PROCESS_SHARED </p> </blockquote> <p> Fixes the problem. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion Gaztañaga</dc:creator> <pubDate>Fri, 13 Sep 2013 20:27:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6108#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6108#comment:6</guid> <description> <p> BOOST_INTERPROCESS_POSIX_PROCESS_SHARED is not fixing anything as Mac Os does not support POSIX process-shared synchronization primitives. </p> <p> Starting in <a class="changeset" href="https://svn.boost.org/trac10/changeset/85401" title="Fixes #9008">[85401]</a> revision, all synchronization primitives based on spinlocks (for systems like Windows or Mac Os that don't support native process-shared synchronization primitives placed in shared memory) use an improved wait strategy, starting with a raw loop+yields for a OS tick (typically 10ms) and going to sleep after that. It has improved the performance and in most cases and CPU usage is very low. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 13 Sep 2013 22:48:43 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6108#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6108#comment:7</guid> <description> <p> igaztanaga, on 10.8, it appears that Mac is now supporting posix shared memory constructs for synchronisation. Perhaps you should check it. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion Gaztañaga</dc:creator> <pubDate>Fri, 13 Sep 2013 23:40:06 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6108#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6108#comment:8</guid> <description> <p> Mac OS defines in unistd.h _POSIX_THREAD_PROCESS_SHARED but the function "pthread_mutexattr_setpshared" is not available according to: </p> <p> <a class="ext-link" href="https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/index.html"><span class="icon">​</span>https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/index.html</a># </p> <p> And even some other similar functions' man page </p> <p> <a class="ext-link" href="https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/pthread_rwlockattr_setpshared.3.html"><span class="icon">​</span>https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/pthread_rwlockattr_setpshared.3.html</a> </p> <p> says: BUGS The PTHREAD_PROCESS_SHARED attribute is not supported. </p> <p> Can you show me any page that shows that 10.8 has real support for THREAD_PROCESS_SHARED? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 13 Sep 2013 23:47:59 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6108#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6108#comment:9</guid> <description> <p> I found in the 10.8 SDK: </p> <p> usr/include/pthread.h:int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int ); </p> <p> But whether or not it is actually available is another question. </p> <p> That man page is from 1998, has it actually been updated? </p> <p> I can't give you a really good detail right now, but I DID have good success by manually defining </p> <p> #define BOOST_INTERPROCESS_POSIX_PROCESS_SHARED </p> <p> in my project, CPU usage went down significantly (basically to 0) and everything was working, as expected. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 13 Sep 2013 23:54:16 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6108#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6108#comment:10</guid> <description> <p> Okay, so I just ran a test case, got a positive result on 10.8.4 </p> <p> <a class="ext-link" href="http://codeshare.io/ULnXr"><span class="icon">​</span>http://codeshare.io/ULnXr</a> </p> <p> It DOES appear to be working correctly. </p> <p> Let me know if you'd like me to test some other APIs. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion Gaztañaga</dc:creator> <pubDate>Sat, 14 Sep 2013 10:05:19 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6108#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6108#comment:11</guid> <description> <p> Thanks for the test. I've found reports on the net that shows that Mac Os 10.6 does not support it: </p> <p> <a class="ext-link" href="https://git.reviewboard.kde.org/r/102145/diff/?expand=1"><span class="icon">​</span>https://git.reviewboard.kde.org/r/102145/diff/?expand=1</a> <a class="ext-link" href="http://alesteska.blogspot.com.es/2012/08/pthreadprocessshared-not-supported-on.html"><span class="icon">​</span>http://alesteska.blogspot.com.es/2012/08/pthreadprocessshared-not-supported-on.html</a> </p> <p> I'm glad version 10.8 supports it. I can't find a definitive information about version 10.7 yet, but I've found this suggesting "pthread_mutexattr_setpshared" is supported (but we don't know if it returns EINVAL ;-) ) </p> <p> <a class="ext-link" href="https://gist.github.com/2bits/2720855"><span class="icon">​</span>https://gist.github.com/2bits/2720855</a> </p> <p> If anyone can run your test in Mac Os 10.7 it would be very nice and I could try to activate pthread process-shared mutexes for 10.7 and newer versions. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 14 Sep 2013 12:39:14 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6108#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6108#comment:12</guid> <description> <p> I don't reach to get the test. Ion, coul dyou add it to the regression test so that I can run it explicitly? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 14 Sep 2013 12:39:29 GMT</pubDate> <title>cc set https://svn.boost.org/trac10/ticket/6108#comment:13 https://svn.boost.org/trac10/ticket/6108#comment:13 <ul> <li><strong>cc</strong> <span class="trac-author">viboes</span> added </li> </ul> Ticket Ion Gaztañaga Sun, 15 Sep 2013 18:57:38 GMT <link>https://svn.boost.org/trac10/ticket/6108#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6108#comment:14</guid> <description> <p> Vicente confirmed Mac Os 10.7 also passes your testcase successfully. I think the correct solution would be to detect the minimum Mac Os requirements for the build, checking the value of MAC_OS_X_VERSION_MIN_REQUIRED. Something like: </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#if defined(__APPLE__)</span> <span class="cp">#include</span> <span class="cpf">&quot;TargetConditionals.h&quot;</span><span class="cp"></span> <span class="c1">//Check we&#39;re on Mac OS target</span> <span class="cp">#if defined(TARGET_OS_MAC)</span> <span class="cp">#include</span> <span class="cpf">&quot;AvailabilityMacros.h&quot;</span><span class="cp"></span> <span class="c1">//If minimum target for this compilation is older than Mac Os Lion, then we are out of luck</span> <span class="cp">#if MAC_OS_X_VERSION_MIN_REQUIRED &lt; 1070</span> <span class="cp">#define BOOST_INTERPROCESS_BUGGY_POSIX_PROCESS_SHARED</span> <span class="cp">#endif</span> <span class="cp">#endif</span> <span class="cp">#endif</span> </pre></div></div><p> If the SDK targets for Mac Os Lion or newer, then native process-shared mutexes will be available. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion Gaztañaga</dc:creator> <pubDate>Sun, 15 Sep 2013 19:38:09 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6108#comment:15 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6108#comment:15</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/85685" title="Detect Mac Os version and allow process-shared synchronization ...">[85685]</a>) Detect Mac Os version and allow process-shared synchronization primitives when minimum target is Mac Os Lion or newer (refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6108" title="#6108: Bugs: Boost interprocess lock consumes 100% CPU on OS X (closed: wontfix)">#6108</a>). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 25 Jan 2017 15:25:13 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6108#comment:16 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6108#comment:16</guid> <description> <p> This ticket is helpful thanks. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 31 Jan 2017 10:47:00 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6108#comment:17 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6108#comment:17</guid> <description> <p> Employees tracking developing issue losing time-on the Web during work-hours is becoming this type of typical software problem facing supervisors and <a class="ext-link" href="http://www.eworksmanager.co.uk/time-tracking-software.html"><span class="icon">​</span>business people</a> the phrase continues to be created to explain it.Some reports claim that U.S. employees invest around 20% or even more of each and every workday performing duties that are individual about the Internet. </p> <p> Evidently, many people is going to do almost anything to prevent function, including bank buying and spending expenses, studying climate reviews and regional information, speaking with friends and family through social networking sites.Contemplating all of the cravings offered from the Web, it is no surprise that is becoming this type of problem for management. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>mazhar</dc:creator> <pubDate>Tue, 14 Feb 2017 05:29:01 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6108#comment:18 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6108#comment:18</guid> <description> <p> As per Vicente confirmation Mac Os 10.7 also passed this testcase successfully. Me too feel the correct solution would be to detect the minimum Mac Os requirements for the build, checking the value of MAC_OS_X_VERSION_MIN_REQUIRED. </p> <p> I'm happy that version 10.8 supports it now. I can't find exact info about version 10.7 yet, but I've found this suggesting "pthread_mutexattr_setpshared" is supported. If you found more on this please let me know if you want icici london swift code see <a class="ext-link" href="http://www.banks-swiftcodes.com/unitedkingdom/icci-uk-ltd-london/swift-code/36659"><span class="icon">​</span>it here</a>. </p> <p> I have also found it useful to manually define something like this </p> <p> #define BOOST_INTERPROCESS_POSIX_PROCESS_SHARED </p> <p> I got it from 10.8 SDK sr/include/pthread.h:int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int ); but I am wondering if I can customize it to use it for my code. </p> </description> <category>Ticket</category> </item> </channel> </rss>