Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Barak_H_Intel
Employee
192 Views

Task Priority In TBB

Jump to solution
Hi,

How to implement aLong ,low priority task in TBB?

In my application i havesome process tasks ,
and1 very long task that sholud run in the bacground until finished.

The long task should be in low priority and interupted when a process task needs to run.

How do i set the priority of the task?

Can anyone help?
0 Kudos
1 Solution
jimdempseyatthecove
Black Belt
192 Views
Quoting - barakhr
Hi,

How to implement aLong ,low priority task in TBB?

In my application i havesome process tasks ,
and1 very long task that sholud run in the bacground until finished.

The long task should be in low priority and interupted when a process task needs to run.

How do i set the priority of the task?

Can anyone help?

When the long low priority task has I/O statements (or other statements that suspend execution) then as Bartolome suggests create an additional thread (not part of TBB pool).

When the long low priority task is completely compute bound then you have two additional options.

1) When the reason for having low priority to this task is for the purpose of permitting other applications to interceed with priority, then when the task starts (top of execute() function) lower your priority. And at bottom of function, restore your priority.

2) When the reason for having low priority task is for the purpose of permitting other tasks in your application to have more run time then you are getting boxed into a corner.
2a) When the other tasks will vary in numbers of threads required (at times using less than number of hardware threads) then oversubscribe the TBB thread pool by one thread and use option 1.
2b) When other tasks will consume computational resources then use other option to create non-TBB thread.
2c) when not running your long low priority task, schedule a NULL task that runs like your long low priority task (lowers priority at start, restores at end) and which performs a loop with Sleep(0) and test for requirement to run long low priority task.

The goal is effective thread subscription.

Jim Dempsey

View solution in original post

4 Replies
Bartlomiej
New Contributor I
192 Views
It can hardly be done as task scheduling in TBB is non-preemptive.
I'd suggest combining TBB with some other technique, e.g. Pthreads or Bost threads. One of the threads runs the TBB scheduler and the other one is the low-priority server.

jimdempseyatthecove
Black Belt
193 Views
Quoting - barakhr
Hi,

How to implement aLong ,low priority task in TBB?

In my application i havesome process tasks ,
and1 very long task that sholud run in the bacground until finished.

The long task should be in low priority and interupted when a process task needs to run.

How do i set the priority of the task?

Can anyone help?

When the long low priority task has I/O statements (or other statements that suspend execution) then as Bartolome suggests create an additional thread (not part of TBB pool).

When the long low priority task is completely compute bound then you have two additional options.

1) When the reason for having low priority to this task is for the purpose of permitting other applications to interceed with priority, then when the task starts (top of execute() function) lower your priority. And at bottom of function, restore your priority.

2) When the reason for having low priority task is for the purpose of permitting other tasks in your application to have more run time then you are getting boxed into a corner.
2a) When the other tasks will vary in numbers of threads required (at times using less than number of hardware threads) then oversubscribe the TBB thread pool by one thread and use option 1.
2b) When other tasks will consume computational resources then use other option to create non-TBB thread.
2c) when not running your long low priority task, schedule a NULL task that runs like your long low priority task (lowers priority at start, restores at end) and which performs a loop with Sleep(0) and test for requirement to run long low priority task.

The goal is effective thread subscription.

Jim Dempsey

View solution in original post

Barak_H_Intel
Employee
192 Views

Thanks for your help,

My case is (2) - Low and high priority tasks in one application,
it's a video processing application with "Process" thread that must be finished ina desired time frame,
And the longlow priority task needs to work "only when time is available" ,
I need the ability to interupt it when new frame arrives.


I hoped that therewill bea solutioninsideTBB ,
i'll have to use something else to prioritze my threads.

thanks,
Barak

vu64
Beginner
192 Views
Quoting - barakhr

Thanks for your help,

My case is (2) - Low and high priority tasks in one application,
it's a video processing application with "Process" thread that must be finished ina desired time frame,
And the longlow priority task needs to work "only when time is available" ,
I need the ability to interupt it when new frame arrives.


I hoped that therewill bea solutioninsideTBB ,
i'll have to use something else to prioritze my threads.

thanks,
Barak


Use Boost.Threads for native threads when you have to. The API is easy and most of it has been incoporated into the C++0x standard.
Reply