Re: To thread or not to thread ?
Yechezkel Mett wrote:
James Kanze wrote:
JohnQ wrote:
No one said TerminateThread was being used for "orderly shutdown".
Obviously
it is "violent" termination of a thread.
I know. That's what the documentation says. So what do you
use? I couldn't find anything like pthread_cancel in the
Microsoft documentation.
You use a "shutdown" event, and every blocking operation in the thread
uses WaitForMultipleObjects with the shutdown event as one of the objects.
:)
One day, it will be discovered that this technique is not simply "a"
way to do it, but "a way to do it that makes the programmer feel really
good about having done it that way." IOW, it is not simply convenient.
It is borderline fundamental.
This is what I meant about WaitForMultipleObjects and its equivalents
on other OS's. Once the programmer has had a taste of it, there is no
turning back. Multi-threading, even in a "complex" application with 25+
threads, no longer seems complex at, not any more than say, a recursive
function with multiple points of return.
The beauty of this technique is that it integrates naturally with the
C++ constructor/destructor model and it is entirely based on a library
with no modification to the language itself.
Of course, one would want to make the interface is clean so that it
readily ports from OS to OS, and one might impress upon the kernel-mode
designers of the target OS that such a primitive is a not merely a
peculiarity of one particular OS but necessity for all multi-tasking
OS's in general.
-Le Chaud Lapin-
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]