On Wed, 28 Sep 2011 16:55:41 -0700 (PDT), JRR <j...@cisco.com> wrote:
>Greetings all, > >I have inherited some AMQ CPP client code. Recently we started seeing random >crashes when ActiveMQCPP::initializeLibrary() was being invoked. These >crashes do not always occur. > >I used [gdb] and the information relating to this crash is as follows: > >------------------------------------------------------------ > >------------------------------------------------------------ > >I have started reading through the AMQ CMS CPP documentation, but I don't >see any documentation for the initializeLibrary() method. > >However, I do see in code examples, that this initializeLibrary() method is >being invoked as one of the first operations in main(). > >In the code that I've inheritted, the AMQ client code is abstracted way down >in a helper class and they >invoke the initializeLibrary() every time they are getting read to make a >connection to the broker. > >I have a theory that initializeLibrary() should be invoked once and only >once. Moreover to make matters >worse, its possible for multile instances of one of our client AMQ objects >to execute at the same time, since we are a multi-threaded SMP system. > >I see a comment in our code above the call that simply says: > // initializeLibrary() is thread-safe. >however I haven't seen any documentation to prove or disprove this, nor have >I found any documentation to explain how the initializeLibrary() method >should be used. > >Can anyone point out documentation for this method? It's mentioned in the reference guide: <http://activemq.apache.org/cms/api_docs/activemqcpp-3.2.5/html/classactivemq_1_1library_1_1_active_m_q_c_p_p.html#ab5b19bf0ceea3b2c32de1cef256da397> As a general principle only assume that a method is thread safe iff the documentation says so. The default case is always to assume things are not thread safe. Your problem could easily be caused by a race condition so I would delete the comment and make it thread safe. And I would recommend only calling it once. It can't do any harm.