Boost logo

Boost Users :

Subject: Re: [Boost-users] [interprocess] Is there a bug in spinlock atomic implementations 1.39 and 1.40?
From: K. Noel Belcourt (kbelco_at_[hidden])
Date: 2009-10-19 12:03:09


Hi Vladimir,

On Oct 14, 2009, at 7:13 AM, Sakharuk, Vladimir wrote:

> Steven, Thanks!
> If I can not use detail folder is there other ways I can use atomic
> based spinlock?

It's not in Boost, but the Intel Threading Building Blocks has an
atomic class that you could use to implement an atomic spinlock.
Perhaps something like this might work?

// atomic's have no constructors but you can reply on their being
zero initialized
tbb::atomic<int> ai;

...

while(1) {
   if (1 == ai.compare_and_swap(1, 0)) {
     // ...
     --ai; // atomic decrement
     break;
   }
}

-- Noel


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net