Boost logo

Boost :

From: Bill Klein (bill_at_[hidden])
Date: 2001-06-28 16:40:10


Jeremy Siek wrote:
> If you want to join, you don't create a detached thread in the first
> place, and you don't need to detach in the destructor because the
> join does the cleanup. Note I'm using POSIX threads definitions
> here.
>
> I have a bad feeling that a lot of time is being wasted because some
> people are talking Win32 and some are talking POSIX. I'm currently
> printing out the MSDN docs to figure out the relation between the
> Win32 defs and the POSIX defs.

I use both pthreads and Win32 threads so that's not the problem. I'll
try restrict what I say here to posix wording. :)

You're suggesting that the boost thread library should allow you to
create a thread "already detached" like pthreads does. Ok, even
supposing this was a good idea, what if you didn't create the thread
"already detached" (with the intention of joining some time later) but
then forgot to join. The destructor will still need to detach to do
resource cleanup.

But enough of that, I don't think we need to be adding an extra
parameter to create_thread() to specify that it's already detached,
because you can do it oh so much more elegantly then that by
detaching in the destructor of the ref. You want to create an
already detached thread? Try this:

    create_thread( whatever );

Because you've ignored the return value its destructor was called and
it was detached. Exactly what one would expect with a call like that:
the thread is being created and let go to do its own thing. You want
to join at some later point?

    ref thread = create_thread( whatever );
    ...
    ...
    thread->join();

You can't lose!


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