Boost logo

Boost :

From: David Maisonave (dmaisonave_at_[hidden])
Date: 2006-04-18 14:25:24


"Eric Niebler" <eric_at_[hidden]> wrote in message
news:<443FF065.9020809_at_[hidden]>...
>
> I'm thinking about replacing some uses of shared_ptr with
> intrusive_ptr,
> but I've got questions. One of the nice things about shared_ptr is the

> lock-free thread-safe ref counting. I want my intrusive_ptr to have
the
> same safety and efficiency, but I don't see how to get it. I see
> $boost_root/detail/atomic_count.hpp, but shared_ptr doesn't use it.
Why
> not? And why is it in detail/? Should I not consider using it?
>
> Taking in the bigger picture, intrusive_ptr requires people to write
> their own add_ref and release functions, most of which will probably
end
> up using ++ and -- on a plain integer. This is totally broken in
> multi-threaded applications, right? Isn't it dangerous to not provide
> complementary utilities for correctly managing reference counts? It
> seems to me intrusive_ptr is impossible to use safely and portably.
What
> have I missed?

Check out the policy base smart pointer class in the following link:
http://axter.com/smartptr/

This smart pointer uses an intrusive_lock_policy to synchronize both
intrusive and non-intrusive smart pointers.
Although intrusive_lock_policy uses intrusive logic, it still can work
with any type by using the mutex_wrapper class.
http://axter.com/smartptr/classmutex__wrapper.htm
http://axter.com/smartptr/structintrusive__lock__policy.htm

The mutex_wrapper class adds intrusive logic to any type.

I believe the same can be done to the boost::intrusive_ptr class.
It shouldn't be that hard to add a wrapper-class to boost that would
give intrusive logic to any type.
Example usage:
boost::intrusive_ptr<intrusive_wrapper<vector<int> > > spVect = new
boost::intrusive_wrapper<vector<int> >();

See following link for mutex_wrapper implementation:
http://axter.com/smartptr/sync__wrapper_8hpp-source.htm


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