Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::weak_ptr usage in multithreaded environments
From: Peter Dimov (pdimov_at_[hidden])
Date: 2010-02-01 10:22:32


Virgil Palanciuc wrote:
> Hello all,
>
> [long story short: I'd like to know whether a weak_ptr.lock() counts
> as a "shared pointer read" or as a "shared pointer write" ]

It is a "const" member function and counts as a read.

> I'm using boost shared pointers in an multi-threaded app. Basically,
> my app maintains a "forest" of "context trees" - i.e. I have a map
> from a "file name" to a "global context" that organizes the
> information for that file.
> The "global context" in the map is basically the root node of a tree
> of "local contexts" in that file. The tree is kept with
> boost:shared_ptr<> on the way down (father-son relations) and
> boost::weak_ptr<> on the way up (son->father pointers).
>
> I have added proper synchronization to the data structure... I think.
> I use reader/writer locks (only one writer allowed, but arbitrary
> number of readers) and I'm still getting sporadic crashes, especially
> when constructing a "global context" (root node) shared_ptr<> from a
> weak_ptr<> - using lock().

Would it be possible to extract a simplified example in which the crashes
still occur?


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