Boost C++ Libraries: Ticket #10180: shared_memory_object assertion when used with boost unit test https://svn.boost.org/trac10/ticket/10180 <p> I am running with Visual Studio 2010, and boost 1.55. When I run a simple unit test with shared_memory_object, I get an assertion on shutdown. The test itself creates a shared memory object, maps it to memory, and writes to it; it then opens a shared memory object of the same name and reads from it. This works fine. </p> <p> On exit, the fini_atomic_func functor in intermodule_singleton_common is run to clean up. This does the following: </p> <pre class="wiki"> ref_count_ptr *rcount = intermodule_singleton_helpers::thread_safe_global_map_dependant &lt;ThreadSafeGlobalMap&gt;::find(m_map, typeid(C).name()); //The object must exist BOOST_ASSERT(rcount); </pre><p> The assertion fails. In the debugger I can see that typeid(C).name() has returned a rubbish string, and therefore no map entry is found. When that same code is executed in init_atomic_func, typeid(C).name() returns "struct boost::interprocess::ipcdetail::windows_bootstamp" as expected. Following the relevant memory address in the debugger, I see that the typeid string is erased in the unit test's framework::shutdown() function. This is done deliberately to eliminate fake memory leak reports from the typeid strings. See boost\test\impl\framework.ipp. </p> <p> Unfortunately the interprocess cleanup is done via a handler registered with std::atexit, which guarantees it will be after framework has run shutdown. I don't see any options on either side (boost unit test or boost interprocess) which would allow the order to be fixed up. </p> <p> Simplest code to reproduce: </p> <pre class="wiki">#include &lt;boost/test/unit_test.hpp&gt; #include &lt;boost/interprocess/shared_memory_object.hpp&gt; namespace IP = boost::interprocess; BOOST_AUTO_TEST_SUITE( TestSharedMemory ) BOOST_AUTO_TEST_CASE( CauseAssertionFailure ) { IP::shared_memory_object lShared( IP::open_only, "test_string", IP::read_only ); BOOST_REQUIRE( lShared.get_name() != 0 ); } BOOST_AUTO_TEST_SUITE_END() </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10180 Trac 1.4.3 andrew.lang@… Tue, 08 Jul 2014 01:16:03 GMT component changed; owner set https://svn.boost.org/trac10/ticket/10180#comment:1 https://svn.boost.org/trac10/ticket/10180#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Ion Gaztañaga</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">interprocess</span> </li> </ul> <p> Setting the component to interprocess; could also be considered a unit test problem. </p> <p> This doesn't happen on Linux. </p> Ticket Ion Gaztañaga Wed, 30 Jul 2014 15:02:21 GMT <link>https://svn.boost.org/trac10/ticket/10180#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10180#comment:2</guid> <description> <p> I don't see any option to fix this if Boost.Test prevents correct cleanup code in atexit(),as typeid should be available. However, please test Boost 1.56 RC, the global singleton logic is now triggered lazily and if boost.Test does the cleanup in a global destructor, Interprocess cleanup might be performed before that. </p> </description> <category>Ticket</category> </item> </channel> </rss>