Re: Posix thread exiting and destructors
On Apr 10, 10:31 am, "Boltar" <boltar2...@yahoo.co.uk> wrote:
I'm writing a threading class using posix threads on unix with each
thread being run by an object instance. One thing I'm not sure about
is , if I do the following:
: do stuff
If I exit the thread at the end of the destructor will all the memory
used for the object be free'd?
Maybe. C++ doesn't define threading, so it doesn't say what
would happen here, and Posix doesn't define a C++ binding, so
each implementation is on its own. In a somewhat similar (but
not precisely identical) situation, I found that Sun CC and g++
(both under Solaris) behaved differently.
My suspicion is it won't and I actually need to exit the
thread outside of the object itself, but I thought I'd check
on here first.
I'd forget about pthread_cancel and pthread_exit within C++.
Make other arrangements, throwing an exception when you want to
terminate. Catch the exception in the `extern "C"' function you
used to start the thread, and go on from there.
It's also not too clear to me what kind of a class could want to
do an exit in its destructor. pthread_exit has semantics more
or less like throwing an exception, and that's generally
something you want to avoid in a destructor. Please explain
what you're trying to do.
James Kanze (GABI Software) email:email@example.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34