Community
cancel
Showing results for 
Search instead for 
Did you mean: 
poetinha
Beginner
48 Views

The proper way to cancel a ConcurrentQueue's Pop condition and his consumer thread

Hi folks,

I'm currently migrating to TBB, anyway, I will have the same question... I've attached my sources to explain.

My consumer thread could be waiting on a queue.pop(), since it should be signaled on concurrent queue only... what's the better way to deal with this? I know that a queue will never have a terminate() method :P it's just a workaround for now.

Thanks in advance,

William

concurrent_queue-inl.h

test_consumer.h
0 Kudos
5 Replies
nagy
New Contributor I
48 Views

Something like this maybe?
void terminate()
{
queue.push(nullptr);
}
void run()
{
History* hist = queue.pop();
bool terminated = hist == nullptr;
}
poetinha
Beginner
48 Views

pushing a NULL value works only on a blockingqueue, right?
nagy
New Contributor I
48 Views

I dont understand? pop() is blocking in all tbbs concurrent queues, try_pop is non-blocking. And why would it only work on a blockingqueue?
poetinha
Beginner
48 Views

My mistake. Thanks a lot. It solved my problem.
Dmitry_Vyukov
Valued Contributor I
48 Views

Quoting poetinha
My mistake. Thanks a lot. It solved my problem.

Be careful, some use patterns can corrupt memory/crash:

http://software.intel.com/en-us/forums/showthread.php?t=73928&o=d&s=lr

Reply