Fast inter-thread communication mechanism
Asked Answered
A

3

7

I need a fast inter-thread communication mechanism for passing work (void*) from TBB tasks to several workers which are in running/blocking operations. Currently I'm looking into using pipe()+libevent. Is there a faster and more elegant alternative for use with Intel Threading Building Blocks?

Abdu answered 8/3, 2010 at 6:58 Comment(0)
L
7

You should be able to just use standard memory with mutex locks since threads share the same memory space. The pipe()+libevent solution seems more fitting for interprocess communication where each process has a different memory space.

Lizliza answered 8/3, 2010 at 14:51 Comment(1)
Thanks for your reply. I guess I'll use concurrent_bounded_queue for that :)Abdu
O
2

Check out Implementing a Thread-Safe Queue using Condition Variables. It uses an STL queue, a mutex, and a condition variable to facilitate inter-thread communication. (I don't know if this is applicable to Intel Threading Building Blocks, but since TBB is not mentioned in the question/title, I assume others will end up here like I did -- looking for an inter-thread communication mechanism that is not IPC. And this article might help them, like it helped me.)

Openwork answered 23/8, 2010 at 16:33 Comment(0)
J
1

Take a look at the Boost lock free and thread safe queue. Very easy to use and works really well. I've used it with threads running on separate cores polling the queue for work.

http://www.boost.org/doc/libs/1_55_0/doc/html/lockfree.html

Jaymie answered 23/11, 2013 at 12:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.