
Chris Thomasson wrote:
Sent: Wednesday, November 22, 2006 11:32 PM To: boost@lists.boost.org Subject: Re: [boost] Preliminary working prototypeofatomic_shared-- multithreaded wrapper for shared_ptr.
"Talbot, George" <Gtalbot@locuspharma.com> wrote in message news:acfee74296c36aa7458ec7c5580b0b9c4564c67b@locuspharma.com...
Hi,
I've attached to this e-mail a working prototype of a wrapper for shared_ptr that uses a spinlock so that the shared_ptr may be updated atomically from multiple threads. For example, two threads can both attempt to set the value of the same shared_ptr, and the last one will win. This wrapper includes a "compare_and_set" method for performing lock-free-style "read, copy, attempt swap, repeat" updating to a data structure, though, of course because the wrapper uses a spinlock, it isn't truly lock free.
I suggest you take a look at a mostly lock-free implementation:
http://appcore.home.comcast.net/vzoom/refcount/
Your wrapper uses the spinlock when it doesn't have to... A swap and a cas > to shared locations that contain pointers to the refcount object do not need to be locked...
I know. I was just doing a simple prototype first that has the interface that I want. I figure if I get everything working with the simple stupid spinlock, then I can go back and re-work with atomic operations.
Weak reference count modifications do not need to be locked...
That's good to know.
You don't need to use DWCAS either...
Don't I need to do that for assignment and compare_and_set for the actual shared_ptr<>, since it's two words? (pointer to object and pointer to refcount.) This is good feedback. Thank you for the help. -- George T. Talbot gtalbot@locuspharma.com