Boost logo

Boost :

From: Greg Colvin (gcolvin_at_[hidden])
Date: 2001-06-21 22:21:13


From: Beman Dawes <bdawes_at_[hidden]>
> At 09:56 PM 6/21/2001, Greg Colvin wrote:
>
> >> Which would people prefer, and why?
> >>
> >> The id/handle/pointer/link copyable semantics?
> >
> >Yes please.
>
> Why? Do you see a thread as different that a file, or do you think them
> similar and wish iostreams had chosen handle semantics?
>
> It is OK with me to chose the handle semantics, but we will need clear
> rationale since it seems a bit unusual for C++.

If one has only the non-copyable thread object then one
is tempted to traffic in raw pointers to that object, with
either the usual risks of dangling pointers or else the
requirement to keep the thread object around forever.

Thus my suggestion of the interface

   thread_ptr thread::create(...)

where thread_ptr is a smart pointer to a thread object
whose lifetime is managed behind the scenes. Of course
one could perhaps just as well do

    shared_ptr<thread> tp = thread::create(...);

with the interface

   auto_ptr<thread> thread::create(...)

to discourage abuse of raw pointers.

But I'm not sure if any of this is really any better than a
simple, copyable, lightweight thread_ref object.


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