Boost C++ Libraries: Ticket #4524: interprocess::interprocess_semaphore consumes cpu while waiting https://svn.boost.org/trac10/ticket/4524 <p> If wait() blocks, thread which executes wait() on interprocess_semaphore consumes cpu (possibly in loop doing thread_yield) </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4524 Trac 1.4.3 Gennady Proskurin <gprspb@…> Tue, 10 Aug 2010 19:28:08 GMT attachment set https://svn.boost.org/trac10/ticket/4524 https://svn.boost.org/trac10/ticket/4524 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">sem.cc</span> </li> </ul> <p> When main thread sleeps in sleep(), thread thr1 does wait() on semaphore and consumes cpu while waiting. </p> Ticket Gennady Proskurin <gprspb@…> Tue, 10 Aug 2010 19:31:51 GMT <link>https://svn.boost.org/trac10/ticket/4524#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4524#comment:1</guid> <description> <p> My system: </p> <p> % uname -a FreeBSD gpr.nnz-home.ru 9.0-CURRENT FreeBSD 9.0-CURRENT <a class="missing ticket">#0</a> r211020M: Sun Aug 8 11:06:03 MSD 2010 gpr@…:/usr/obj/usr/src/freebsd-head/sys/GPR amd64 </p> <p> % g++ -v Using built-in specs. Target: amd64-undermydesk-freebsd Configured with: FreeBSD/amd64 system compiler Thread model: posix gcc version 4.2.1 20070719 [FreeBSD] </p> <p> boost 1.43 from freebsd ports </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Rohit Joshi</dc:creator> <pubDate>Wed, 11 Aug 2010 21:40:05 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4524#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4524#comment:2</guid> <description> <p> Event I have the same issue. When I replaced my semaphore (sem_t) with boost semaphore object, cpu utilization was much higher even while waiting on semaphore. I changed it back to my semaphore class and it solved the problem so issue is with boost semaphore. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Rohit Joshi</dc:creator> <pubDate>Wed, 11 Aug 2010 21:40:47 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4524#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4524#comment:3</guid> <description> <p> Forgot to mentioned that I use boost 1.43.0 </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Rohit Joshi</dc:creator> <pubDate>Tue, 17 Aug 2010 20:57:29 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4524#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4524#comment:4</guid> <description> <p> Any information on when would this fix be available? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion Gaztañaga</dc:creator> <pubDate>Tue, 24 Aug 2010 10:51:41 GMT</pubDate> <title>milestone changed https://svn.boost.org/trac10/ticket/4524#comment:5 https://svn.boost.org/trac10/ticket/4524#comment:5 <ul> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.44.0</span> → <span class="trac-field-new">Boost-1.45.0</span> </li> </ul> <p> FreeBSD does not define _POSIX_SEMAPHORES so Interprocess was not using sem_xxx for named semaphores. However FreeBSD supports sem_xxx with some bugs: </p> <p> <a class="ext-link" href="http://www.freebsd.org/cgi/man.cgi?query=sem_open&amp;apropos=0&amp;sektion=0&amp;manpath=FreeBSD+9-current&amp;format=html"><span class="icon">​</span>http://www.freebsd.org/cgi/man.cgi?query=sem_open&amp;apropos=0&amp;sektion=0&amp;manpath=FreeBSD+9-current&amp;format=html</a> </p> <p> BUGS </p> <blockquote> <p> This implementation places strict requirements on the value of name: it must begin with a slash (`/'), contain no other slash characters, and be less than 14 characters in length not including the terminating null character. </p> </blockquote> <p> Interprocess for Boost 1.45 will use sem_xxx family if FreeBSD is detected. </p> Ticket Gennady Proskurin <gprspb@…> Tue, 24 Aug 2010 19:25:46 GMT <link>https://svn.boost.org/trac10/ticket/4524#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4524#comment:6</guid> <description> <p> It seems that man pages on freebsd site are outdated. This bugs have been fixed. <a class="ext-link" href="http://svn.freebsd.org/viewvc/base?view=revision&amp;revision=201884"><span class="icon">​</span>http://svn.freebsd.org/viewvc/base?view=revision&amp;revision=201884</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion Gaztañaga</dc:creator> <pubDate>Thu, 26 Aug 2010 10:24:55 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/4524#comment:7 https://svn.boost.org/trac10/ticket/4524#comment:7 <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">fixed</span> </li> </ul> <p> Fixed for Boost 1.45 in release branch </p> Ticket Gennady Proskurin <gprspb@…> Sat, 02 Jul 2011 06:03:25 GMT status, version changed; resolution deleted https://svn.boost.org/trac10/ticket/4524#comment:8 https://svn.boost.org/trac10/ticket/4524#comment:8 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>version</strong> <span class="trac-field-old">Boost 1.44.0</span> → <span class="trac-field-new">Boost 1.46.1</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> <p> Reproduced with boost-1.46.1 in FreeBSD-9 (the same system). The same problem with timed_wait(). </p> Ticket Gennady Proskurin <gpr@…> Thu, 25 Aug 2011 16:36:00 GMT version changed https://svn.boost.org/trac10/ticket/4524#comment:9 https://svn.boost.org/trac10/ticket/4524#comment:9 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.46.1</span> → <span class="trac-field-new">Boost 1.47.0</span> </li> </ul> <p> At quick glance seems that freebsd does not define _POSIX_THREAD_PROCESS_SHARED, but defines _POSIX_SEMAPHORES, so BOOST_INTERPROCESS_POSIX_PROCESS_SHARED is not defined and BOOST_INTERPROCESS_POSIX_NAMED_SEMAPHORES is defined. At file interprocess_semaphore.hpp there is a check for both BOOST_INTERPROCESS_POSIX_PROCESS_SHARED and BOOST_INTERPROCESS_POSIX_NAMED_SEMAPHORES.<br /><br /> I'm not sure why BOOST_INTERPROCESS_POSIX_PROCESS_SHARED is checked for semaphores. After reading posix docs I think it is for interprocess mutexes and condvars, semaphores are process-shared by definition. Patch for boost 1.47 attached, it fixes bug for me (on freebsd). </p> Ticket Gennady Proskurin <gpr@…> Thu, 25 Aug 2011 16:36:47 GMT attachment set https://svn.boost.org/trac10/ticket/4524 https://svn.boost.org/trac10/ticket/4524 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">ipc_sem.patch</span> </li> </ul> <p> Patch for fixing bug </p> Ticket anonymous Sun, 16 Dec 2012 15:33:13 GMT <link>https://svn.boost.org/trac10/ticket/4524#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4524#comment:10</guid> <description> <p> #include &lt;boost/interprocess/detail/workaround.hpp&gt; #undef BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION #include &lt;boost/interprocess/sync/interprocess_semaphore.hpp&gt; </p> <p> int _tmain(int argc, _TCHAR* argv[]) { </p> <blockquote> <p> interprocess_semaphore sem; </p> </blockquote> <p> } </p> <p> This code can work and cpu is normal, but build with runtime-link-static,it will detect memory leaks. </p> <p> my system is vs2008 sp1. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion Gaztañaga</dc:creator> <pubDate>Thu, 30 Jun 2016 20:18:29 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/4524#comment:11 https://svn.boost.org/trac10/ticket/4524#comment:11 <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> Closing this old bug as current version (since Boost 1.55) uses efficient spinlocks with waits when the interprocess semaphore is emulated </p> Ticket