Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

working with priorities (TBB/Boost combined)

inshi1
Beginner
412 Views

Hi,

I'm using TBB combined with Boost.Thread, but I'm not sure I'm using it right. the scenario is as follows:

Our application main's goal is to receive and analyze UDP packets, for that I've used tbb pipeline with several filters (filters

receiving data from the network and filters analyzing the data).

besides that, I have other maintenance and various actions I want to run parallel to the described pipeline, but with lower priority (the pipeline should have the highest priority).

in order to do so I did the following (semi-pseudo code):

boost::thread thr1( boost::bind( &udpPipelineManager::receiveAndHandlePackets, &u1 ) );
boost::thread thr2( boost::bind( &Class1::otherAction1, r1 ) );

boost::thread thr3( boost::bind( &Class2:otherAction2, r2 ) ); ......

ChangePriority(thr1, 99);
ChangePriority(thr2, 50);

ChangePriority(thr3, 20);

thr1 is the thread running the TBB pipeline with many tasks in parallel.

Is this the right way to do it? I have 4 cores, I want the other actions to run on 1 core without distrubing (too much) the pipeline tasks.

**** also, what the threads scheduler policy should be (SCHED_RR, SCHED_FIFO, etc.)?

Thanks,

Lior.

0 Kudos
3 Replies
RafSchietekat
Valued Contributor III
412 Views

I don't know what the default is (perhaps it's best to leave all TBB work at default priority), but if you want to affect the priority of TBB work you should use task_scheduler_observer to repeat the action for all worker threads. Also, if any other threads then use TBB, you may run into priority-inversion issues.

0 Kudos
inshi1
Beginner
412 Views

can you please elaborate? (example would be best :) )

I didn't understand how the task_scheduler_observer can control the priority of the other tasks/threads?

also, what about the scheduling policy?

Thanks.

0 Kudos
RafSchietekat
Valued Contributor III
412 Views
task_scheduler_observer notifies you when threads are (de)activated, so you should be able to execute some code of your own that affects their priority, I think. I suggest you try first and then come back if you run into a specific problem.
0 Kudos
Reply