Boost logo

Boost :

From: Ross Smith (ross.s_at_[hidden])
Date: 2001-06-22 15:25:54


Greg Colvin wrote:
>
> For threads the typical use is to spawn a thread and forget
> about it, with the expectation that it will do whatever it
> needs to do and go away on its own when it is done.

That's a _very_ dangerous strategy! If main() exits first, the thread
gets stabbed in the back (at least on Unix -- I think Windows keeps the
process alive as long as there are any threads still running). Granted
there are times when you want to do that, but I certainly wouldn't call
it the _typical_ use.

> Yes, and that might be one way to solve it. I think the catch
> is that if you have created a thread and retained no references
> to it you may want it just go away when its function exits.

It sounds as though you're assuming that the object's lifetime must be
the same as the thread's lifetime. I don't think that's necessary; just
call pthread_detach() in the destructor if the thread hasn't been joined
yet (under pthreads; on Windows it doesn't matter, you just call
CloseHandle() regardless).

(Then again, possibly I'm not the best guy to be putting his oar in at
the moment; I'm not very keen on what I've seen of the Boost threads
library so far, so clearly your aims are different to mine.)

-- 
Ross Smith <ross.s_at_[hidden]> The Internet Group, Auckland, New Zealand
========================================================================
"Unix has always lurked provocatively in the background of the operating
system wars, like the Russian Army."                  -- Neal Stephenson

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk