What you think if I'd ask you to change the Thread class a bit so that it could notify a Listener on thread completion and also it could pass an exception on, thrown in a thread, to the notification callback. Just like C# BackgroundWorker class does. This C# class always call a callback on completion through caller's message queue on any thread completion (allowing you to call any other GUI functions safely), including thread cancelation and thread exceptions. As I roughly see, it's possible to change source code this way:
If you are not going to implement the discribed functionality or if I'm not aware of something that is already implemented in JUCE and could be used to bring the functionality to my view then tell me how to acheive that without the proposed changes.
Doesn't really feel like something that belongs in the thread class, when you could just have a one-line call at the end of your run() method that triggers a callback. What's the actual use-case that you have in mind when asking for this?
It's not just one line. Callback must be called always on any completion. Like BackgroundWorker class says: RunWorkerCompleted event occurs when the background operation has completed, has been canceled, or has raised an exception.
I do not want to use timers or other workaround approaches just to figure out that a thread completed its job and a result is ready to use. I want to let my app to run smoothly (without any blocking) and react to a result only when it's ready. Just read the BackgroundWorker class documentation to see what it's capable of.
Yes, that's a good way to do it! I wish everyone had a C++11 compiler so I could start using that kind of trick in the library!
I guess the only danger with it would be if the thread object were to get deleted before the message arrives, when it'd call a dangling pointer.
Your original request for a callback built into the thread class isn't a bad idea - it just feels like this kind of lambda-based callback is a more modern approach.