Boost C++ Libraries: Ticket #9466: shared_ptr fails with EINVAL on AIX 7.1 when compiled with atomic https://svn.boost.org/trac10/ticket/9466 <p> Boost shared_ptr sometimes fails with EINVAL (22) when compiled with gcc 4.6.3 (65bits) on AIX 7.1. It appears that this failure only occurs when atomic is activated as part of building the boost library (1.55). </p> <p> I noticed on AIX the library "libboost_atomic" was req'd, while that was not needed on other platforms such as rhel and ubuntu. </p> <p> To solve the issue on AIX I specified -DBOOST_THREAD_DONT_USE_ATOMIC while building the boost libs. </p> <p> Inside details: </p> <hr /> <p> Line 73 at boost/boost/smart_ptr/detail/lwm_pthreads.hpp BOOST_VERIFY( pthread_mutex_lock( &amp;m_ ) == 0 ); </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9466 Trac 1.4.3 Peter Dimov Tue, 03 Dec 2013 16:25:56 GMT <link>https://svn.boost.org/trac10/ticket/9466#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9466#comment:1</guid> <description> <p> Interesting. I can't think of a mechanism by which libboost_atomic could cause shared_ptr to fail in such a manner. Furthermore, on AIX shared_ptr doesn't use pthread_mutex by default: </p> <pre class="wiki">#elif defined( _AIX ) # include &lt;boost/smart_ptr/detail/sp_counted_base_aix.hpp&gt; </pre><p> Trying to lock an invalid mutex can be a symptom of an ODR violation. If some .cpp files are compiled with BOOST_SP_USE_PTHREADS and some others aren't, it's possible for a .cpp file in the first group to try to lock a pthread_mutex which doesn't exist because a shared_ptr created by a .cpp file in the second group doesn't have it. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 03 Dec 2013 17:24:40 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9466#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9466#comment:2</guid> <description> <p> hmm, i,m not really convinced. If I build the boostlibs on aix or e.g. linux, using the same bootstrap params then clearly only on aix the atomic lib is build, and needs to be linked. Thats not the case on linux. </p> <p> Futhermore for debuggung purposes I added some stdout logging inside the lwm_pthread.hpp. On linux that filw was not used, however on aix is is, thats where i notice the EINVAL(22) return value. </p> <p> If however on aix I specify the BOOST_THREAD_DONT_USE_ATOMIC, than it wont be using lwm_pthead.hpp. In which case the behaviour is identical to the linux build. </p> <p> I can provide some logging to tomorrow if you need it? </p> <p> Regards, -- Pat -- </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Tue, 03 Dec 2013 21:31:08 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9466#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9466#comment:3</guid> <description> <p> The Boost.Atomic library is apparently used by Boost.Thread in its implementation of call_once, which is why it probably needs to be linked. But it's not used by shared_ptr. You will need to identify what calls into lwm_pthread.hpp, because shared_ptr is not the only component that uses it. Can you provide a stack trace? </p> </description> <category>Ticket</category> </item> <item> <author>pat <pat@…></author> <pubDate>Wed, 04 Dec 2013 12:20:34 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/9466 https://svn.boost.org/trac10/ticket/9466 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">readme</span> </li> </ul> Ticket pat <pat@…> Wed, 04 Dec 2013 12:24:55 GMT attachment set https://svn.boost.org/trac10/ticket/9466 https://svn.boost.org/trac10/ticket/9466 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">build-boost-aix71-12583090-debug.log.tar.gz</span> </li> </ul> Ticket pat <pat@…> Wed, 04 Dec 2013 12:25:08 GMT attachment set https://svn.boost.org/trac10/ticket/9466 https://svn.boost.org/trac10/ticket/9466 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">build-boost-aix71-15663342-debug.log.tar.gz</span> </li> </ul> Ticket pat <pat@…> Wed, 04 Dec 2013 12:25:24 GMT attachment set https://svn.boost.org/trac10/ticket/9466 https://svn.boost.org/trac10/ticket/9466 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">build-boost_x86_64-pc-linux-rhel6-gnu-64-debug.log.tar.gz</span> </li> </ul> Ticket pat <pat@…> Wed, 04 Dec 2013 12:25:36 GMT attachment set https://svn.boost.org/trac10/ticket/9466 https://svn.boost.org/trac10/ticket/9466 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">build-ilona-aix71-11796734-debug.log.tar.gz</span> </li> </ul> Ticket pat <pat@…> Wed, 04 Dec 2013 12:25:47 GMT attachment set https://svn.boost.org/trac10/ticket/9466 https://svn.boost.org/trac10/ticket/9466 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">build-ilona-aix71-16121982-debug.log.tar.gz</span> </li> </ul> Ticket pat <pat@…> Wed, 04 Dec 2013 12:26:00 GMT attachment set https://svn.boost.org/trac10/ticket/9466 https://svn.boost.org/trac10/ticket/9466 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">build-ilona_x86_64-pc-linux-rhel6-gnu-64-debug.log.tar.gz</span> </li> </ul> Ticket pat <pat@…> Wed, 04 Dec 2013 12:26:11 GMT attachment set https://svn.boost.org/trac10/ticket/9466 https://svn.boost.org/trac10/ticket/9466 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">callstack.log</span> </li> </ul> Ticket pat <pat@…> Wed, 04 Dec 2013 12:28:44 GMT <link>https://svn.boost.org/trac10/ticket/9466#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9466#comment:4</guid> <description> <p> Okay, check the provided attachments (I had to compress due to upload size limits). The readme file explains what we did, and refers to the various log files. </p> <p> Regards, -- Pat -- </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 04 Dec 2013 12:40:43 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9466#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9466#comment:5</guid> <description> <p> Does ilona use boost::call_once before main, that is, in a static constructor? </p> </description> <category>Ticket</category> </item> <item> <author>pat <pat@…></author> <pubDate>Wed, 04 Dec 2013 13:21:20 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9466#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9466#comment:6</guid> <description> <p> no we don't use the call_once ... </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Wed, 04 Dec 2013 14:17:40 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9466#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9466#comment:7</guid> <description> <p> As far as I can see, BOOST_THREAD_DONT_USE_ATOMIC only affects boost::call_once, forcing it to not use Boost.Atomic. So something must be using call_once. It's possible that some Boost library is using it internally. </p> <p> What I think happens is the following. Boost.Atomic, under AIX, falls back to its generic lock pool implementation in boost/atomic/detail/lockpool.hpp and libs/atomic/src/lockpool.cpp. This uses boost::lightweight_mutex, and consequently lwm_pthreads.hpp. </p> <p> The mutex pool (a static array of 41 lightweight_mutex objects) is defined in libs/atomic/src/lockpool.cpp. However, since lightweight_mutex has a constructor calling pthread_mutex_init and a destructor calling pthread_mutex_destroy, it is possible for call_once to end up using this mutex pool before it's constructed or after it's destroyed, depending on static initialization order. </p> <p> If I'm correct in this assumption, then your workaround of defining BOOST_THREAD_DONT_USE_ATOMIC is the right one for now. We'll see how we can fix the problem on our side. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Wed, 04 Dec 2013 14:19:08 GMT</pubDate> <title>owner changed https://svn.boost.org/trac10/ticket/9466#comment:8 https://svn.boost.org/trac10/ticket/9466#comment:8 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Peter Dimov</span> to <span class="trac-author">viboes</span> </li> </ul> <p> Vicente, do you have any ideas? Does my analysis appear correct? </p> Ticket Andrey Semashev Wed, 04 Dec 2013 15:03:09 GMT cc set https://svn.boost.org/trac10/ticket/9466#comment:9 https://svn.boost.org/trac10/ticket/9466#comment:9 <ul> <li><strong>cc</strong> <span class="trac-author">Andrey.Semashev@…</span> added </li> </ul> Ticket Andrey Semashev Wed, 04 Dec 2013 15:16:40 GMT <link>https://svn.boost.org/trac10/ticket/9466#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9466#comment:10</guid> <description> <p> Peter, you are correct that in case if lock pool is used in Boost.Atomic it cannot be safely used in global initializers. I'd like to fix that. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Wed, 04 Dec 2013 15:20:31 GMT</pubDate> <title>owner changed https://svn.boost.org/trac10/ticket/9466#comment:11 https://svn.boost.org/trac10/ticket/9466#comment:11 <ul> <li><strong>owner</strong> changed from <span class="trac-author">viboes</span> to <span class="trac-author">Andrey Semashev</span> </li> </ul> Ticket Peter Dimov Wed, 04 Dec 2013 15:42:35 GMT component changed https://svn.boost.org/trac10/ticket/9466#comment:12 https://svn.boost.org/trac10/ticket/9466#comment:12 <ul> <li><strong>component</strong> <span class="trac-field-old">smart_ptr</span> → <span class="trac-field-new">atomic</span> </li> </ul> Ticket Andrey Semashev Sat, 14 Dec 2013 15:47:29 GMT <link>https://svn.boost.org/trac10/ticket/9466#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9466#comment:13</guid> <description> <p> Should be fixed in git: <a class="ext-link" href="https://github.com/boostorg/atomic/commit/9ded906200ea83ceb24b1be007ed14da262e5ea0"><span class="icon">​</span>https://github.com/boostorg/atomic/commit/9ded906200ea83ceb24b1be007ed14da262e5ea0</a>. Please, try if it helps. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrey Semashev</dc:creator> <pubDate>Tue, 07 Jan 2014 11:37:54 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/9466#comment:14 https://svn.boost.org/trac10/ticket/9466#comment:14 <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> Merged to master in <a class="ext-link" href="https://github.com/boostorg/atomic/commit/1fc5d75a980143e5f43f94df45efa419e73e88f1"><span class="icon">​</span>https://github.com/boostorg/atomic/commit/1fc5d75a980143e5f43f94df45efa419e73e88f1</a>. </p> Ticket