Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ - Passing data between threads

I have a thread pool consists of 4 threads: t1, t2, t3, and t4. They are running concurrently, but the input from t3 and t4 depends on output from t2. How should I implement message queue so that after t2 completes, it will send the output data to t3 and t4 for processing? I have tried to implement the message queue using locking mechanism, but it seems that the locking is quite expensive. Is there lock-free mechanism that pass data between threads? I am using boost::thread in visual studio 2010.

like image 671
OhMyGosh Avatar asked Sep 29 '22 09:09

OhMyGosh


1 Answers

Boost has a lock-free queue: http://www.boost.org/doc/libs/1_56_0/doc/html/lockfree.html.

like image 88
Tomo Avatar answered Oct 04 '22 03:10

Tomo