WARNING: the new application currently can run the main thread and 4 worker threads, which cripples my dual-core machine while it is running so please be careful running all the workers at once.
Here is the link:
http://rapidshare.com/files/416108723/ThreadTest2.zip
Lets say that the application is a representation of a restaurant. I am the boss and I have 4 workers to do something. Working can be anything, taking orders, making sandwiches, waiting tables, ect. So I can see how much work each worker has done and I know how much total work has been completed.
Right now it is not perfect as the work counter restarts every time. I have not changed the worker process from your code yet. It would make more sense that each time I just give more work by increasing the work limit. (I know I am a bad boss)
Something that is not included yet is that all the workers should be aware of each other in the sense if one or several workers finish, they should help the other workers finish their work by taking some of the load. In code, lower the working limit and increase their limit and keep working. Also, there should be a break option, meaning that if a worker stops for a break, it should notify the other workers and they should work until it returns.
This is the easier case, the only problem is accurately checking the status of other workers.
There is another piece I have not included yet. There should be another data source that I technically cannot control which is my product provider.
This is a restaurant and to do work I need raw materials that I get from this external worker. For a sandwich I need 2 slices of bread, lettuce, pickles, tomato, ketchup and mustard, which is provided by other thread. The problem is that it is only one thread and it needs to supply products to all the threads.
Further more, I need to keep track of the produce I have available and when needed order more, and notify the workers if we are short some produce, to make less of the related products.
It really becomes an issue to not overload or overcall the supplying worker. All I technically need is one thread to be boss and handle the drawing, and one other thread between all the workers, assuming it makes it easier to work with the provider thread.
I know my explanation is not very clean and neither is my code. Hopefully it makes some sense though.
Please tell me what you think and if I can improve the current design.
I will try to enhance the application and try to better explain how it should run.
Thanks again.