From: David Maisonave (dmaisonave_at_[hidden])
Date: 2006-04-18 14:25:24
"Eric Niebler" <eric_at_[hidden]> wrote in message
> I'm thinking about replacing some uses of shared_ptr with
> 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
> 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.
> 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
> 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.
> have I missed?
Check out the policy base smart pointer class in the following link:
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.
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.
boost::intrusive_ptr<intrusive_wrapper<vector<int> > > spVect = new
See following link for mutex_wrapper implementation:
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk