Re: Multithreading questions
"Dave Cullen" <nospam@mail.com> wrote in message
news:%23GeQf1OhHHA.1244@TK2MSFTNGP04.phx.gbl
From what I've read, the worker thread must return or call
AfxEndThread from within itself. What happens if the main thread
terminates first?
The code inside the runtime that called your WinMain will call
EndProcess soon after WinMain returns. At this point, all other threads
still running will be terminated. In general, it is a good idea for the
main thread to instruct all the worker threads to shut down (you should
design some mechanism for that at the outset) and wait until they
terminate, before main thread itself terminates.
If the machine hangs and the user is forced to do something ugly like
CTRL-ALT-DEL does that kill both threads?
Yes. It terminates the process and all threads in it.
I can either allow the worker thread to run continuously and
communicate through synchronization objects, or run and terminate
each time it's needed. What's the preferred method and the tradeoffs
for these choices?
I don't think it will make any noticeable difference.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925