|
Boost : |
From: Timothy Ritchey (tritchey_at_[hidden])
Date: 2005-08-09 18:56:43
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]
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk