Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all

I’m trying to parallelize a part of our application but I have some problems….

I need to calculate N jobs. Resources for one job are that big that it is not possible to prepare all N jobs and let them afterwards process by several threads. Therefore I need to feed a limited job queue with M items (where M is pretty much smaller than N)

So what I need to manage is:
1.) There are N Jobs to execute
2.) There is a job queue with maximal M items, feed by a producer thread (?)
3.) There is a thread pool with K worker threads waiting for work

How can I manage/synchronize all these?

- Who will assign/invoke a worker thread its work?
- Should a worker thread -after finishing its job- check the job queue by itself for new work? Or should the worker thread simply go to a “waiting list” and another thread dispatches pending work to worker threads?

Does somebody know a pattern for this?

Thank you very much in advance.
Regards, idle63
Posted
Comments
Mehdi Gholam 4-Oct-13 10:46am    
You have described what you should do, so where are you stuck?
[no name] 7-Oct-13 11:20am    
I got stuck on a lot of details. But once again, especially in my own laziness ... to lazy to think through every detail exactly.
Thanks for your kick, it helped realy! Regards, idle63

1 solution

Have a look at a the Producer-Consumer Dataflow Pattern:
http://msdn.microsoft.com/en-us/library/hh228601.aspx[^]

Good luck!
 
Share this answer
 
Comments
[no name] 4-Oct-13 15:13pm    
Thank you very much for this.
Kind regards, idle63

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900