Boost logo

Boost :

From: Hoeffner, Detlef (Detlef.Hoeffner_at_[hidden])
Date: 2002-04-03 11:53:55


Hi William,

> However, I understand the convenience of this and so
> I'll add something soon. Thanks for the suggestion.

Thanks!

> The only thing missing in boost::thread from your list is
> operator<<(ostream&, ).

I still do not see how I would identify the current instance of thread.
Am I missing something?

> I'm going to work around this by using a TSS pointer value,
> which seems to be the best solution, though it's not a perfect solution.

I guess for performance issues it would be preferable to use functions the
operating system or the thread library provides, e.g.

  static thread_id getCurrentThreadId()
  {
#ifdef POSIX_THREADS
    return pthread_self();
#elif WIN32_THREADS
   return GetCurrentThreadId();
#endif
  }

Regards

Detlef

-----Original Message-----
From: William Kempf [mailto:williamkempf_at_[hidden]]
Sent: Mittwoch, 3. April 2002 17:05
To: boost_at_[hidden]
Subject: RE: [boost] Thread locals

>From: "Hoeffner, Detlef" <Detlef.Hoeffner_at_[hidden]>
>Reply-To: boost_at_[hidden]
>To: "'boost_at_[hidden]'" <boost_at_[hidden]>
>Subject: RE: [boost] Thread locals
>Date: Wed, 3 Apr 2002 16:37:41 +0200
>
>
> > As a substitute, try using the comparison operator for the boost::thread
> > class. This can fill the gap in many (but not all) cases where you are
> > managing the set of threads yourself.
>
>I need this mainly for tracing purposes in spots where I have no knowledge
>of the current instance of thread. This does not seem to help me in that
>case.
>
> > On some platforms (i.e. pthreads), the "thread_id" is actually an opaque
> > type (pthread_t) rather than a numeric value, and I think that is why no
> > such operation is exposed in the current version of the library.
>
>It is however possible to provide a class threadid, that has dependent on
>the
>platform different members but provides operations as ==, !=,
>operator<<(ostream&, ), ... That would be fine to solve the problem.

The only thing missing in boost::thread from your list is
operator<<(ostream&, ). That's actually the tricky one to do portably. The

pthread_t opaque type provides no way to output a unique textual
representation. I'm going to work around this by using a TSS pointer value,

which seems to be the best solution, though it's not a perfect solution.

BTW, there's another operation needed for thread_id that you didn't
mention... it needs to be copy constructable.

Bill Kempf
williamkempf_at_[hidden]

_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com

_______________________________________________
Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost


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