
We are using shared_ptr extensively in our application, and seem to be having some threading issues. In particular, we have an Envelope class that is used to hold messages received over the network. We use Spirit to parse the message string and construct the Envelope object, then we pass is on to the EnvelopeController, which holds a thread pool to handle all of the Envelopes. These Envelopes are passed around as shared_ptr<Envelope> between these different components. In essense, we have one thread that is receiving the message from the network stack, parsing it, and passing it to the thread_pool, which is then using one (or more) additional threads to actually deal with the contents of the envelope. On a Uni-processor box, everything works great. All of our envelopes are being destroyed properly. On a multi-processor machine, none of the envelopes are getting destroyed. We are in a situation where two shared_ptrs to the same underlying object may go out of scope and need to decrement the ref count at the same time. Is the in the realm of "undefined behavior?" Am I using the shared_ptr incorrectly? Thanks for any advice. Thread 1 --------- { shared_ptr<Envelope> envelope(new Envelope(...)); ... [pass envelope to Thread 2] ... [envelope goes out of scope] } Thread 2 -------- void process(shared_ptr<Envelope> envelope) { [do work on envelope] [envelope goes out of scope] }

Timothy Ritchey wrote:
We are using shared_ptr extensively in our application, and seem to be having some threading issues. In particular, we have an Envelope class that is used to hold messages received over the network. We use Spirit to parse the message string and construct the Envelope object,
Your problems might be caused by Spirit. Quite recently, a bug was fixed that causes an internal structure of Spirit to be initialized in a thread unsafe manner. The fixed code will get released very soon with Boost 1.33 and also with the standalone Spirit package. You also should #define BOOST_SPIRIT_THREADSAFE as described in the grammar section of Spirit's documentation. HTH, m Send instant messages to your online friends http://au.messenger.yahoo.com

Thank you for the pointer. I was able to get the problem worked out my upgrading to a newer release of the Intel compiler. I will take a look at the Spirit issue since we do use it to parse all of our messages. We do have BOOST_SPIRIT_THREADSAFE defined in all our projects. I've compiled with 1.33 and we seem good to go with it. Thanks again, Tim On Aug 10, 2005, at 12:53 AM, Martin Wille wrote:
Your problems might be caused by Spirit. Quite recently, a bug was fixed that causes an internal structure of Spirit to be initialized in a thread unsafe manner. The fixed code will get released very soon with Boost 1.33 and also with the standalone Spirit package.
You also should #define BOOST_SPIRIT_THREADSAFE as described in the grammar section of Spirit's documentation.
HTH, m Send instant messages to your online friends http:// au.messenger.yahoo.com _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/ listinfo.cgi/boost
participants (2)
-
Martin Wille
-
Timothy Ritchey