|
Boost Users : |
From: olivier_debels
Date: 2002-12-16 16:02:03
--- In Boost-Users_at_[hidden], "William E. Kempf" <wekempf_at_c...>
wrote:
>
> olivier_debels said:
> >
> > I'm using boost_1_29_0 and need to get the id of the current
thread.
>
> Why?
>
I have several threads which pop messages from the queue. I want to
keep track of what each thread pops (depending on some rules) without
adding an extra parameter (threadId) in the pop-function.
By this way threads just call the pop-function (they don't know
anything about the internal cooking of the queue). They get a
message, which fulfills the rules (one of the rules is f.e. that no
two threads can handle the same message at the same time).
> > Is there a way to get the id of the current thread using boost? I
> > don't see how I can access the current thread (Is there some sort
of
> > current function?).
>
> No. This isn't a portable feature. I plan on adding a feature
that's
> similar, and portable, but that's why asked why you need this. I'm
not
> sure the portable interface will suffice for your needs with out
knowing
> what they are.
>
> > If I could access the current thread, I could write a getId()
> > function (in a class subclassed from boost::thread). Only problem
> > there is the return type. It seems the id is an int in windows
> > environment, a pthread_t in POSIX and a MPTaskID in MACOS.
Those last
> > two seems to be pointers to struct. I guess it is possible to
cast all
> > of them to long (using reinterpret casting), but maybe I am
overlooking
> > something then.
>
> Casting this way is non-portable. And I don't believe POSIX
requires
> pthread_t to be a pointer, though I haven't researched that in
depth yet.
>
I guessed this would not be portable...
> William E. Kempf
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net