0

I am trying to schedule tasks in multi threaded systems. my idea is to have a local queue per thread, each thread will fetch the job from its local queue. But when the thread reaches some threshold, it should not fetch the job, rather it should transfer the job to a thread which is below the threshold level.

My doubt is how to set the threshold for the threads.

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Rd7
  • 45
  • 2
  • 9
  • 2
    There's not enough information here to answer your question. You haven't specified the platform or programming language you are using, for starters, and I don't know what you mean by "threshold." – Robert Harvey Dec 12 '12 at 16:44
  • i am working on C++ programming language in microsoft visual studio. And threshold in the sense, when a thread is very busy,it should not fetch the jobs anymore, rather it should transfer the jobs to another thread which is idle. this helps in loadbalancing among the threads. my question is like how to set some limit that a thread wont accept anymore jobs. – Rd7 Dec 12 '12 at 17:25
  • please let me know if it is not still clear, thank you – Rd7 Dec 12 '12 at 17:40
  • Is it good that i can monitor thread stack usage..!! and if the thread uses 100% of its stack memory for a long time. i assume it is very busy and it should not accept any new tasks.. pls help me out i am new to these topics – Rd7 Dec 13 '12 at 16:01

2 Answers2

1

An alternative arrangement to this problem is giving threads who have finished their queue the ability to take work from the queue of others. This is better known as "Work Stealing" and is a well known scheduling algorithm e.g.

http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.38.8905

Tim Lloyd
  • 37,954
  • 10
  • 100
  • 130
  • ya i know about task stealing, but that method is more overhead and have greater latency..! my proposed idea would lower the both, but i have these doubts while implementing – Rd7 Dec 12 '12 at 17:28
  • 1
    I'm not so sure I understand where the extra latency and overhead is involved in "work stealing" vs "work delegation" (your pattern). Could you please explain. – Tim Lloyd Dec 12 '12 at 17:31
  • work stealing can sometimes leads to 'costly remote steals', like thread 1 is idle and thread 8 is busy, stealing from 1st to 8th thread would increase the latency i guess. – Rd7 Dec 12 '12 at 17:39
  • Could you explain 'costly remote steals'. – Tim Lloyd Dec 12 '12 at 17:43
  • Stealing between cores on di↵erent chips reduces performance by incurring higher overhead costs, additional cold cache misses, remote memory access costs, and coherence misses due to false sharing. Another limitation of work stealing is that it does not make the best possible use of caches shared among cores. – Rd7 Dec 12 '12 at 17:55
  • How does work delegation circumvent this? It pushes "work" to other threads, so will have the same problems to overcome. – Tim Lloyd Dec 12 '12 at 18:28
  • i am trying to implement work delegation and compare it with the work stealing method. it may be good than work stealing, but i am not sure.so can you please suggest any ideas how to control the inputs in threads after a certain level. – Rd7 Dec 13 '12 at 10:27
  • Is it good that i can monitor thread stack usage..!! and if the thread uses 100% of its stack memory for a long time. i assume it is very busy and it should not accept any new tasks. – Rd7 Dec 13 '12 at 16:00
  • Measuring whether a thread is using "100% of it's stack memory" has nothing to do with how busy it is. – Tim Lloyd Dec 14 '12 at 14:04
0

What threading library are you using?

I use two OSS libraries in all of my threading projects TBB and Cilk Plus. One feature that these higher level runtimes provide is that they automatically schedule tasks on to threads in a way that make efficient use of processor resources. The runtimes are also very effective at load balancing the many task.

www.threadingbuildblocks.org

www.cilkplus.org

Eugene Roeder
  • 219
  • 2
  • 7