Boost C++ Libraries: Ticket #2391: interprocess_recursive_mutex doesn't work interprocess https://svn.boost.org/trac10/ticket/2391 <p> The recursive mutex tests current thread using detail::get_current_thread_id(), which in turn uses pthread_self(). The latter function returns thread id that unique in context of a process. (As least in CentOS 4.6 'm using.) This results in threads from different processes not being synchronized. Sometimes it results in asserts (in debug build) or exceptions (in release). Attached is a small shared memory test that uses fork() which led me to finding the problem. Environment and test's output: </p> <p> $ g++ -v Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.6/specs Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-<span class="underline">cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=i386-redhat-linux Thread model: posix gcc version 3.4.6 20060404 (Red Hat 3.4.6-10) [sergeys@sergeys-vm32 boosttest]$ g++ bug.cc -o bug -I /mnt/builder/3rdParty/boost/v35.0/include -L /mnt/builder/3rdParty/boost/v35.0/lib32 -l rt </span></p> <p> $ uname -a Linux sergeys-vm32 2.6.9-78.0.1.ELsmp <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/1" title="#1: Bugs: boost.build causes ftjam to segfault (closed: Wont Fix)">#1</a> SMP Tue Aug 5 11:02:47 EDT 2008 i686 i686 i386 GNU/Linux </p> <p> $ g++ bug.cc -o bug -I /mnt/builder/3rdParty/boost/v35.0/include -L /mnt/builder/3rdParty/boost/v35.0/lib32 -l rt </p> <p> $ ./bug parent pthread_self -1208224064 child pthread_self -1208224064 bug: /mnt/builder/3rdParty/boost/v35.0/include/boost/interprocess/sync/emulation/interprocess_recursive_mutex.hpp:97: void boost::interprocess::interprocess_recursive_mutex::unlock(): Assertion `detail::equal_thread_id(detail::get_current_thread_id(), m_nOwner)' failed. Aborted Done child </p> <p> Please note, that when built on different system (CentOS 5), the test runs without assertion. But the mutex still doesn't protext the code as intended. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2391 Trac 1.4.3 Sergey Samsonik <serge_98@…> Tue, 07 Oct 2008 20:30:29 GMT attachment set https://svn.boost.org/trac10/ticket/2391 https://svn.boost.org/trac10/ticket/2391 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">bug.cc</span> </li> </ul> <p> source code to demonstrate the problem </p> Ticket Sergey Samsonik <serge_98@…> Wed, 08 Oct 2008 21:55:32 GMT <link>https://svn.boost.org/trac10/ticket/2391#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2391#comment:1</guid> <description> <p> A little clarification, </p> <p> /* Thread process-shared synchronization is not supported. */ #define _POSIX_THREAD_PROCESS_SHARED -1 </p> <p> in /usr/include/bits/posix_opt.h on my system causes boost/interprocess/sync/emulation/interprocess_recursive_mutex.hpp to be used, which doesn't work with multiple processes as explained above. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion Gaztañaga</dc:creator> <pubDate>Fri, 10 Oct 2008 10:33:47 GMT</pubDate> <title>milestone changed https://svn.boost.org/trac10/ticket/2391#comment:2 https://svn.boost.org/trac10/ticket/2391#comment:2 <ul> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.37.0</span> → <span class="trac-field-new">To Be Determined</span> </li> </ul> <p> Thanks for the report. The code for "generic" recursive mutex suposses thread id is unique for all system threads, which is true for windows but not for POSIX (some implementations yes, others not). So the solution is not easy and boost 1.37 is around the corner, so it must delayed for a future release. Suggestions and comments are welcome. </p> Ticket Sergey Samsonik <serge_98@…> Fri, 10 Oct 2008 14:30:38 GMT <link>https://svn.boost.org/trac10/ticket/2391#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2391#comment:3</guid> <description> <p> This is not a showstopper for me any longer since the systems I'm working with now (CentOS/RedHat 4.5+) implement Posix shared mutexes, even thought /usr/include/bits/posix_opt.h states it otherwise. There's another /usr/include/<strong>nptl</strong>/bits/posix_opt.h header, which defines correct values for these systems. -I/usr/include/nptl compiler option addressed the problem in this case. </p> <p> I don't know it it's possible or how, a solution (at least a temporary one) may be disabling generic (interprocess) recursive mutexes on systems where thread ids are not unique. </p> <p> Also, the problem looks very similar to the one in ticket <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/1390" title="#1390: Bugs: Interpocess: managed shared memory failing completely under OS X (closed: fixed)">#1390</a> here. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion Gaztañaga</dc:creator> <pubDate>Wed, 24 Dec 2008 22:08:42 GMT</pubDate> <title>status, milestone changed; resolution set https://svn.boost.org/trac10/ticket/2391#comment:4 https://svn.boost.org/trac10/ticket/2391#comment:4 <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> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.38.0</span> </li> </ul> <p> Changed code so that the thread identifier is an structure with the pid and the thread id. </p> Ticket