working with priorities (TBB/Boost combined)

working with priorities (TBB/Boost combined)


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



4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Raf Schietekat's picture

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.

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?


Raf Schietekat's picture

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.

Login to leave a comment.