
Hi George, On Wed, Jul 23, 2008 at 6:04 AM, Talbot, George <Gtalbot@locuspharma.com> wrote:
A while back (~2006 I think) I was asking around on this list about using boost::shared_ptr<T> to build a composite data structure that can be accessed and modified by multiple threads.
Peter Dimov's suggestion at the time was to write a wrapper class for boost::shared_ptr<T> that would protect access to the boost::shared_ptr<T> with a spinlock. I've done this, and this works pretty good in my application. I'm interested in contributing this code to BOOST, as it's been quite useful.
I have a few questions:
1) Is there interest in such a donation. It's just one header file, and it's wafer-thin...
I am interested, although I do have some reservations with it not using the locks already available in Boost.Thread.
2) If so, how does one go about making such a donation?
(I think it's a little funny that you use 'donation' instead of contribution... but nonetheless... ;-) )
From what I gather, this is something that may have to go through a mini-review. The veterans can answer this question better though.
3) My implementation below uses a spinlock to protect things and as one might expect, under load my application does spend some time in ::pthread_spin_lock(). Is there a way to rewrite this class (possibly with friendship of boost::shared_ptr<T>) in a lock-free manner? I've attached the code below...
I'm not sure about lock-free approaches, but doesn't shared_ptr<T> already use atomic operations when built in multi-threaded mode? Another issue I see is the dependence to ::pthread_spin_lock() -- can you use a shared recursive_mutex instead? HTH -- Dean Michael C. Berris Software Engineer, Friendster, Inc.