Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fast inter-thread communication mechanism

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?

like image 315
Stan Avatar asked Mar 08 '10 06:03

Stan


2 Answers

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.

like image 90
Jason B Avatar answered Oct 02 '22 09:10

Jason B


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.)

like image 28
Mark Rajcok Avatar answered Oct 02 '22 10:10

Mark Rajcok