$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: William Kempf (sirwillard_at_[hidden])
Date: 2000-11-27 10:34:31
--- In boost_at_[hidden], "Michael D. Crawford" <crawford_at_g...> wrote:
> > And
> > then there's multithreading.
>
> I know it take extra effort, but you can do reference counting with
> multithreading. The ZRef reference counted smart pointer in ZooLib
handles
> multithreading correctly.
>
> You could probably lift out ZRef and ZAtomic from ZooLib and use
them on
> their own for multithreaded reference counting without using the
rest of
> ZooLib. http://zoolib.sourceforge.net
>
> It does this by using atomic addition and subtraction on the
reference
> counts when it's getting operated on. So if you have two threads
> incrementing and decrementing the reference count it does the right
thing.
I've not looked at ZooLib (yet!), but I can tell you that if all that
was done were to use atomic increment and decrement on the ref-count
then the smart pointer is *NOT* thread safe. Copies also must copy
the pointer, and if the whole operation isn't protected I don't see
how it can be thread safe (though maybe I'm missing some subtle
ordering of operations that might achieve this).
> It wasn't easy for Andy Green to get it right, considering also the
cross-
> platform issues (and we found a small compiler bug when doing the
atomic
> operations) but it does seem to work correctly.
Then we should look here for ideas for Boost Threads as well.
Bill Kempf