Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
2401 Discussions

best pattern for long-time working threads

Dmitry_Dobryak
Beginner
93 Views
Hi!

My program must have 3 threads which working during whole programs life in parallel. They must communicate each other. What is the best pattern for this? task:enqueue?
Something like this:
LongTask* t = new (tbb::task::allocate_root())LongTask();

LongTask* t1 = new (tbb::task::allocate_root())LongTask();
LongTask* t2 = new (tbb::task::allocate_root())LongTask();
tbb::task:enqueue(*t);
tbb::task:enqueue(*t1);
tbb::task:enqueue(*t2);

0 Kudos
2 Replies
Dmitry_Dobryak
Beginner
93 Views
As I understand boost::thread is more suitable in this case because TBB is not guarantee that tasks will run in parallel. But Is it possible to use boost::thread to create threads and tbb concurent containers, tbb sync primitives for use in that boost threads?
RafSchietekat
Black Belt
93 Views
"As I understand boost::thread is more suitable in this case because TBB is not guarantee that tasks will run in parallel."
Correct.

"But Is it possible to use boost::thread to create threads and tbb concurent containers, tbb sync primitives for use in that boost threads?"
Any API to create threads will do (TBB even has its own in anticipation of the latest standard C++ if your compiler does not provide that yet), and you don't even have to make a choice; TBB's other features should work regardless of how the threads were created.
Reply