Boost logo

Boost :

From: williamkempf_at_[hidden]
Date: 2001-09-24 15:13:04


--- In boost_at_y..., "Peter Dimov" <pdimov_at_m...> wrote:
> From: <williamkempf_at_h...>
> > --- In boost_at_y..., "Peter Dimov" <pdimov_at_m...> wrote:
> > > class thread
> > > {
> > > unsigned long id() const; // uniquely identifies the thread
> > > };
> > >
> > > What do you think?
> >
> > I think it's a pain in the @$$ to implement on POSIX ;).
>
> I think that it's doable. You'd need a get_next_id() thread safe
function.

Never said it wasn't doable. In fact your solution actually existed
in earlier Boost.Threads code while I toyed with this method. There
are problems with this, such as the fact that it's at least
theoretically possible to exhaust all such id's if you don't track
which id's no longer have active threads.

> > Seriously, though, I did consider this and rejected it, at least
for
> > the short term, because it is difficult to define for POSIX
> > implementations. The "ID" on POSIX systems is an opaque type,
and is
> > likely a pointer and not an integral value. For most purposes you
> > don't really need this method any way, since we support operators
==
> > and != (I realize this isn't enough for collation, but since
> > boost::thread isn't copyable there's not a lot of need for full
> > collation).
>
> The problem is that I think that I do need it; in Boost.Threads I
can't make
> a std::map<> keyed on a thread, and even if I could (my thread::ref
can be a
> map key) a thread id could be useful for other purposes. For
example, how
> can I implement an errorcheck mutex?

You can't use a thread inside a std::map<> because it's not
copyable. That's why I said I realized that there was not enough
functionality for collation but that there wasn't much need for it.
Even if we fully provided collation it's not useful for your
std::map<> because we can't copy it. Wrap it in a thread::ref or use
pointers instead and you've "automagically" got a value that is
collatable... the pointer. As for errorcheck mutex
implementations... you don't need full collation you only need
equality comparison, which boost::thread has already got.

Bill Kempf


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