Boost logo

Boost Users :

Subject: Re: [Boost-users] Am I doing something wrong here? Boost threads & intrusive_ptr crash
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-06-11 10:19:48


AMDG

Space Ship Traveller wrote:
> <snip>
>
> I'm experiencing a very infrequent crash at the line marked with (*).
> The note is a reference counted pointer (boost::intrusive_ptr), but by
> the time we get here, this pointer is invalid, even though there are
> still references to it in the system. The odd thing is, further up the
> chain (and on the same thread), I'm checking to ensure that note is
> valid, i.e.
>
> //... display update system, separate thread from
> event-loop.
> ensure(ctx->notificationSource);
> loop->postNotification(ctx->notificationSource);
> //...
>
> After writing this far in the email, I'm starting to see something
> where there could be an error. Is it possible that the object
> reference count is being messed up due to multi-threading issues? I.e.
> if the object is being passed around on two separate threads, having
> the reference count incremented and decremented at the same time?
> Actually, it seems obvious that this could be a problem...
>
> Are there any "patterns" for using reference counted objects across
> different threads?

shared_ptr's reference count is thread safe. For intrusive_ptr,
it depends on how you define the reference count.

In Christ,
Steven Watanabe


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