From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-06-27 08:27:52
From: "Beman Dawes" <bdawes_at_[hidden]>
> >Why not use something like
> >namespace thread
> > class id; // or 'desc', if you like
> > id create(...);
> >// etc
> Yes, that sort of low-level interface is the fallback if we can't work out
> a "spirit of C++" interface.
> While I'm really pressing to see if it is possilbe to develop a high level
> interface, I'm not opposed to making the lower level interface public,
> as the C++ standard supports both <cstdio> and <iostream>.
But this low-level, non-C++-spirited interface is nearly equivalent to the
class-based one that Bill posted; that was my point. The user never deals
with 'thread' instances anyway; the thread class is a "glorified namespace",
as Bill correctly noted. The user creates, and manipulates, only thread_desc
instances - this corresponds to thread::id above.
FWIW, I actually like procedural interfaces, when they fit. There is nothing
inherently low-level about them. thread::id may implement the
handle/refcounted body idiom under the hood, or it may be a Win32 HANDLE. In
a way, this interface is higher level, because it hides more of the
The important difference between thread::id and FILE* is that a FILE* may
leak. A thread::id can never leak. It has proper value semantics, so the
'thread reference' it contains will be released upon its destruction; and
the thread will terminate itself when it's done.
thread::id is, using a file based analogy, a FILE* wrapper with the
appropriate copy/destroy semantics.
-- Peter Dimov Multi Media Ltd.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk