I have a program with several worker threads, and a main thread that receives jobs. In the main thread I want to queue the jobs onto a synchronized queue, and have the worker threads sitting there all waiting on the queue. When there’s something in the queue I want the worker to pull the job from the queue, while the remaining work sits there waiting for another job.
I found CreateMsgQueue (http://msdn.microsoft.com/en-us/library/ms885180.aspx) however this appears to only exist for Windows CE.
I know I could write this myself, however if something already existed I’d be a fool not to use it.
I am developing in c++ using Visual Studio 2005.
Any suggestions gratefully received.
Thanks
Rich
Windows doesn’t provide exactly what you want. What it does provide is thread pools — with these, you not only don’t have to create the queue yourself, but you don’t have to create or (directly) manage the threads either.
Of course, synchronized queues do exist too, just not as part of Windows. One I wrote looks like this: