Boost logo

Boost :

Subject: Re: [boost] [lockfree] how many items are queued?
From: Tim Blechmann (tim_at_[hidden])
Date: 2009-09-04 05:29:45


>>>>> lockfree.fifo provides the info if the queue is empty or not.
>>>>
>>>> it is mainly done as debugging help, but it is not supposed to be used
>>>> in concurrent code ...
>>>
>>> Because this function is available I thought it is safe to used it.
>>
>> well, there is a warning in the docs, noting, that this function is not
>> thread-safe :)
>
> I didn't look at your library, but I think that this decision is
> dangerous. I think that this debug functionalities should be enabled
> only if explicitly required by the user, who is assumed to know what
> is doing.

well, the user of the library has to make sure, that this function is
not used in places, where a concurrent access to the queue is possible ...
but, well, even _if_ it would be possible to atomically check, whether a
stack/queue is empty, the result is not valid any more, at the time,
when you use the result:

fifo f;

thread a: bool is_empty = f.empty(); // true
thread b: f.enqueue();
thread a: if (is_empty) do_something(); // fifo is not empty any more

so querying the state of lockfree data structures is always dangerous ...

cheers, tim

-- 
tim_at_[hidden]
http://tim.klingt.org
art is short - life is long
  Jack Kerouac



Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk