Boost logo

Boost Users :

Subject: Re: [Boost-users] Does lock-less queue wait on empty queue ?
From: Gottlob Frege (gottlobfrege_at_[hidden])
Date: 2015-05-21 12:48:16


On Wed, May 20, 2015 at 5:27 PM, Nat Goodspeed <nat_at_[hidden]> wrote:
> On Wed, May 20, 2015 at 5:15 PM, Gottlob Frege <gottlobfrege_at_[hidden]> wrote:
>
>> Using condition variables does require mutexes, but you only need to
>> grab the mutex when someone is actually waiting. So you can have a
>> separate (atomic) flag 'waiting' and then only grab the mutex when it
>> is true.
>>
>> But that is an extra atomic op on every push (checking the flag). Of
>> course, it could probably be a relaxed atomic (I think), which is
>> almost free on many platforms.
>>
>> And it gets tricky ensuring that you don't have a case where someone
>> is waiting but every pusher missed seeing the flag.
>>
>> If the waiting is inside the queue implementation, you can possibly
>> hide the flag inside the head pointer, getting the extra atomic op for
>> free.
>>
>> I touched on some of this in my Lock-free talk at BoostCon/C++Now last week.
>
> Aren't these tricky corner cases what "synchronic" is supposed to address?
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4195.pdf

I think it was more of a way to wrap up "expert waiting" (spinning,
exponential back-off, etc) without each developer needing to
reimplement it.
But it also looks like it could cover my tricky corner cases as well.

(For the specific case of a queue it wouldn't allow me to hide the
extra atomic within the head pointer, and would be an extra
acquire/release, but oh well).

Tony

> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


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