Boost logo

Boost :

From: Dejan Jelovic (djelovic_at_[hidden])
Date: 2001-01-09 05:49:06


Andrew Green wrote:

> The thing that keeps suprising me is just how subtle reference counting is
> once you get into a multi-threaded world. The reference counting
> implementation that's in ZooLib now is SMP-safe in all situations bar one,
> which I'll try to describe.

Actually, this isn't a problem at all.

I've posted a short article explaining this
(http://www.jelovic.com/articles/smart_pointer_thread_safety.htm), but here
is the gist:

The definition of thread safety for smart pointers basically says that it is
safe to use smart pointers from different threads to access a shared
resource. The pointers on separate threads can be dereferenced, manipulated
and destroyed and this will not get you into trouble.

However, in the example you have given the pointer itself is the shared
resource. This is not covered by the thread-safety guarantee, and if you
want to do that then you must use some kind of protocol, just as with any
other shared resource.

In this matter the smart pointers are no worse than native pointers. If one
thread writes to a native pointer and another one reads from it, it's easy
to read a corrupt value.

Dejan


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk