Boost logo

Boost :

From: David Abrahams (root) (abrahams_at_[hidden])
Date: 1999-12-28 08:48:27


scleary_at_[hidden] wrote:
>
> Giora Unger wrote:
>
> > 1. As far as I understand, the library is NOT thread safe.
> > Am I wrong ?
> > For example, let's examine line 169 in smart_ptr.h:
> > if (--*pn == 0) { delete px; }
> > I believe, that in case of two threads concurrently accessing
> > this line (the reset() method), and an initial reference count==2,
> > then a crash is possible: if both decrements occur before both
> > comparisons, resulting in two deletion attempts.
>
> The smart pointers are just as thread-safe as integers.

I don't think that's entirely correct. On many platforms, all integer
operations are atomic; the same can't be said of our smart pointers.

> To use them in a
> thread-safe way, protect them just as you would any other non-thread-safe
> fundamental type/class/library.

Good advice.

> Should we look at doing a portable multi-threading library? I have the
> beginnings of one, but it doesn't allow timed waits or waiting for multiple
> objects -- would these be considered essential or optional?
 
Oh, optional, optional (though highly desired)!
Portable multi-threading is badly needed!

-Dave


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