views:

78

answers:

2

I recently discovered ATL's CThreadPool class and was very happy with this find. It's a neat little class that will take care of the syncronization semantics of having multiple worker threads to process some queue of taks to do. The tasks are fed to the CThreadPool object, by some extrnal process.

Now suppose one of the worker threads encounters an error, or has an exception. I don't mean the type of exceptions where you would want your whole application to just die, but it is something you want to do deal with more gracefully. By gracefully I mean the applicattion can die, but I need to do some clean up work and to put a propper message somewhere as to why it did.

What is the best way to transfer the error info (message, error code, source etc.) to the main thread owning the CThreadPool object?

+2  A: 

If I was working with this system, I would PostMessage from the erroneous task with a custom event that your application's message handler can respond to. You should bundle up whatever information you need in order to properly clean up.

Lyndsey Ferguson
+1  A: 

Use queue with synchronization access for logging all errors and thread for consumer events at queue.

lsalamon