RE: [Boost-users] Re: shared_ptr: LWM versus atomic_count?
Russell Hind
Caleb Epstein wrote:
I've been perusing the source code of
and noticed that it uses the class to do reference counting and not (unless BOOST_NO_MEMBER_TEMPLATES or BOOST_MSVC6_MEMBER_TEMPLATES are defined). Can anyone comment on the reasoning behind using a lightweight mutex-protected counter instead of an atomic counter? I'd think that an atomic counter would be faster, but I suspect that there is a good reason for protecting the count with a mutex. This then begs the question of why use the atomic counter in the situations mentioned above?
If you look at shared_count, you'll see it has to keep track of 2 values, strong_count and weak_count, you can't do this with 'atomic count' so therefore it uses lwm.
It isn't fundamentally necessary to have two counters, though; see <http://groups.google.com/groups?threadm=slrnbhbnpc.154.do-not-spam -benh%40tin.bwsint.com>.
Ben Hutchings wrote:
It isn't fundamentally necessary to have two counters, though; see <http://groups.google.com/groups?threadm=slrnbhbnpc.154.do-not-spam -benh%40tin.bwsint.com>.
I'd seen this (I think you posted the same link recently). I don't know if anything has been done to change the implementation of shared_ptr to use this method, though (nothing to do with me). If the speed increases mentioned are correct, then it certinaly seems a good proposal. Cheers Russell
participants (2)
-
Ben Hutchings
-
Russell Hind