
2 Apr
2013
2 Apr
'13
2:26 p.m.
AMDG On 04/02/2013 03:45 AM, niXman wrote:
Hi,
I read the docs about lockfree::queue::empty() and understang what this way is not safe in multithreaded program. The question is, how can I verify that the queue is empty?
It's impossible. The problem is that by the time you use the answer, the state of the queue may have changed. You can't do better than the built in empty.
Will it be correct the following code?
No. It will re-order the elements if there is more than one.
bool empty() { T *tmp = 0; if ( queue.pop(tmp) ) { queue.push(tmp); return false; } return true; }
In Christ, Steven Watanabe