$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Terence Wilson (tez_at_[hidden])
Date: 2002-06-28 11:46:37
Mmm. I understand that the actual object pointed to must be made thread
safe, however, can I assume that shared_ptr is thread safe? i.e. it will
correctly maintain use counters while being accessed from multiple
threads?
> -----Original Message-----
> From: boost-bounces_at_[hidden] 
> [mailto:boost-bounces_at_[hidden]] On Behalf Of Peter Dimov
> Sent: Friday, June 28, 2002 9:06 AM
> To: boost_at_[hidden]
> Subject: Re: [boost] shared_ptr and thread safety
> 
> 
> From: "Terence Wilson" <tez_at_[hidden]>
> > I'm having some trouble with a container of shared_ptr's shared 
> > between threads. I'm seeing a crash during a pointer access. I have 
> > code something like this:
> >
> > thread 1
> >
> > shared_ptr<CThing> pThing(new CThing);
> > .
> > .
> > pThing->DoSomething();
> > .
> > .
> > pThing=shared_ptr<CThing>(new CThing)
> >
> >
> > thread 2
> >
> > pThing=shared_ptr<CThing>(new CThing)
> > .
> > .
> > pThing->DoSomethingElse();
> >
> > I'm using boost 1_28, Visual Studio 7 and just include the header as
> > follows:
> >
> > #include <boost/smart_ptr.hpp>
> >
> > I don't build the library or declare any symbols.
> >
> > Is there there something special I need to do to make shared_ptr 
> > thread safe? Or am I barking up the wrong tree in terms of 
> my thread 
> > safety expectations?
> 
> Wrong tree. If you replace 'shared_ptr<CThing>' with 
> 'CThing*' in the above, you'll see why it doesn't work. You 
> must synchronize access to pThing (and *pThing, for that 
> matter.) shared_ptr isn't more (or less) thread safe than an 
> "ordinary" pointer.
> 
> 
> _______________________________________________
> Unsubscribe & other changes: 
> http://listarchives.boost.org/mailman/listinfo.cgi/bo> ost
>