Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost.serialization] shared object plugin
From: Robert Ramey (ramey_at_[hidden])
Date: 2012-08-08 13:05:35


Robert Ramey wrote:
> Giampiero Gabbiani wrote:
>> Hi Robert,
>> I tried the test_dll_plugin (with CMAKE under Linux) that seems to
>> cover my case.
>>
>> add_executable(test_dll_plugin test_dll_plugin.cpp
>> polymorphic_base.cpp) target_link_libraries(test_dll_plugin dl
>> boost_serialization boost_filesystem)
>>
>> add_library(plugin_polymorphic_derived2 SHARED
>> polymorphic_derived2.cpp)
>>
>> it compiles (under Linux) but during execution I get:
>>
>> test_dll_plugin: /usr/include/boost/serialization/singleton.hpp:137:
>> static T& boost::serialization::singleton<T>::get_mutable_instance()
>> [with T =
>> boost::archive::detail::extra_detail::guid_initializer<polymorphic_derived2>]:
>> Assertion `! is_locked()' failed.
>>
>
> OK - I looked into this. The key facts are:
>
> I included code assertions which check that all static structures are
> initialized
> before main() is called. I did this to make sure detect any thread
> safey issues
> that might crop up of archives are created on separate threads. This
> code guarentees that the global static list of serializable types is
> not messed with from different threads. I did it this way as I
> didn't want to guard all the serialization calls to check this
> structure with locks - which would be a performance killer.
>
> BUT, this presumes that all DLLs which use the table are loaded
> BEFORE main is called. This the most common case, but it conflicts
> with our usage case. Your usage case is a very important one
> however and it must be supported. And it should be used much
> more often. I'm amazed, surprised, and disappointed that no one
> has spotted this before.
>
> Soooooo
>
> a) just comment out the assertion in your header.
> b) think about this some more.
> c) create a track item for this issue describing the problem and
> proposing a better solution. Something like calling some "other"
> function to turn off the assertion.
>
> Robert Ramey

LOL - looked into this some more.

Turns out that all my test programs call
boost::serialization::singleton_module::lock()
at the beginning of main(). This suggests that your system has some sort of
"delayed" linking which is interesting to know. In any case, this would be
an artifact of the test program rather than your application. So I would
expect your application wouldn't have a problem. You can comment
out the boost::serialization::singleton_module::lock() and it will make the
problem go away in the test program.

Note that the upshot of all this is that using the serialization library
with dynamically loaded types wouldn't be thread safe even though
it is for static linking. This has to be addressed if your ap is going
to use multi-threading and the serialization library and dynamic linking.

Robert Ramey


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net