
Emil Dotchevski <emil@revergestudios.com> writes:
When joining a thread, in case the thread has exited, I find it convenient to have any exception the thread function throws propagated to the caller of join(). Just as an illustration of what I'm talking about, below is my Win32 implementation of a similar interface. An interesting design decision is what to do if a detached thread throws an exception. Note the line marked with (1) -- I've decided to assert in this case (instead of ignoring the exception, which would be the alternative behavior.)
Would something similar be a good addition to Boost Thread?
No. You can easily write code that does this using a wrapper, as you have shown for the win32 API. The futures and packaged_task stuff that I will be merging with boost.thread soon will provide such a wrapper that also allows return values from thread functions. This provides people with a choice --- have the exception terminate the program (and allow a debugger to catch it) which is the default, or allow the exception to propagate by using a packaged_task+future. Anthony -- Author of C++ Concurrency in Action | http://www.manning.com/williams just::thread C++0x thread library | http://www.stdthread.co.uk Just Software Solutions Ltd | http://www.justsoftwaresolutions.co.uk 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976