For a "rough" answer, that was very useful and interesting! These little
demo scripts are a goldmine of information. I have been using threads to
carry out background work while updating a progress bar in the main window
and providing a cancel button. It will be interesting to see Rob's
inter-thread communication code when it's ready.

The situation you describe above is probably going to be the most common win32-gui thread situation, and I'm sure you've gone through a couple of strange workarounds to get this working:)

Rob's code solves several big problems, including how to trigger an event in a thread that is in the windows message loop. Basically, Rob's solution uses a thread safe queue with one end attached to a window (thus, to the thread responding to the events). When an item is added to the queue from a different thread, the window thread responds by firing an event, where you receive the item that was added on the queue. My explanation is poor, but the end results is very simple, event driven, elegant and efficient solution.

One thing I noticed in my program, that also occurs when I run your example,
is that I get a message complaining that "A thread exited while 6 threads
were running" if the main window is exited first. I thought the detach()
method was supposed to prevent that. I seem to remember that when you
actually do a join(), as suggested in the documentation, there are other
problems. Do you also see this? Do you know what is going wrong?

Yes I get this too. I think that the message is mainly a warning, and in most simple cases can be ignored. The correct approach is for all child threads to terminate smoothly, under the control of the main thread before the main thread itself terminates.

Cheers,

jez.



Reply via email to