multithreading - dynamic work allocation for threads in C# -


i'm wanting know how set class dynamically allocate work threads, preferably in c#. i've looked @ [this] ray tracer explanation, don't see description of how look. don't want overly complicated.

i have group of tasks large split evenly , give out threads. want dynamically allocate small portions of tasks each thread, , when threads finish, obtain results , give them more tasks. know did years ago, can't find notes nor have been successful google or here.

any appreciated.

below idea of in pseudo code. it's not going pretty give idea of i'm talking about.

tasklist = arraylist of n tasks resultlist = arraylist of thread results create x threads integer taskscompleted while(taskscompleted < tasklist.size){   thread = next available thread in pool   resultlist.add(thread.results)   taskscompleted += thread.numoftasks   thread.dowork(next set of tasks) } clean threads processresults(resultlist) 

if using .net 4.0+ can use parallel.for method. launches many threads sees necessary parallel process loops. nice thing manages threads , monitors them you. here's how-to introduction parallel for: http://msdn.microsoft.com/en-us/library/dd460713.aspx

you should other constructs task parallel library introduced in .net 4.0. has lot of neat multi-threading helpers make multi-threading lot easier launching , managing own threads. can see msdn docs here: http://msdn.microsoft.com/en-us/library/dd537609.aspx


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -