Re: To thread or not to thread ?
Le Chaud Lapin wrote:
JQP wrote:
Le Chaud Lapin wrote:
I never
thought I would say it, but the thought of not having bona-fide threads
is frightening.
And by that you mean on any other platform or that either Windows or
UNIX is lacking them? By "bona-fide" threads, do you mean real threads
rather than something like pthreads?
Yes and yes.
Why are pthreads not "bona-fide" threads? At the threading
level, they are almost indistiguishable (to the process) from
windows threads. About the only difference is that they offer a
larger variety of synchronization methods.
My system model will fall apart on an OS that does not
have threads. For example, I remember trying to choose between Windows
CE and PalmOs for a "small device" test system. When I saw that Palm
OS did not have multi-tasking, the answer was easy. They do have
Cobalt now, but to not have had it before says something about the OS.
Also, for a while, creating threads in Unix was not as simple as doing
a CreateThread. The newer models like LWP seem to have helped a lot.
What does CreateThread do that pthread_create doesn't? (And I'm
not sure what you mean with regards to LWP. Depending on who's
using the term, LWP is either a synonym for threads, or an
implementation technique invisible to the user.)
[...]
Well that could be put into a thread class (orderly shutdown). Indeed
that would be a reason to wrap the platform abstraction. But yes, other
threading things like locks are the obvious ones to wrap up (one of
mine is called AutoLock which wraps a mutex).
Yep. My thread class includes as part of its design a mechanism for
orderly shutdown. I would not be surprised if the code is the same.
Interesting. Orderly shutdown is one of the things I've not
found in Windows threads. TerminateThread is not an equivalent
of pthread_cancel.
Note that orderly shutdown requires collaboration from the
thread. I'm not sure that it will make it into the standard; in
fact, I rather doubt it will, precisely because there is no
accepted standard way of achieving it.
might be nice to wait for a thread to die. It might be nice to wait
for an event, three mutexes, a semaphore, and 2 threads to die, or any
one of these things to be signaled, etc. I was able to make all
classes RAII, Yin/Yang style (mutexes, etc) except the thread class.
And the reason you couldn't make an RAII-style thread class is....?
Honestly, I cannot remember.
The reason seems obvious, at least for a joinable thread. The
lifetime of the thread is independant of any scope in the
function which creates it.
--
James Kanze (Gabi Software) email: james.kanze@gmail.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]