My advice to you would be not to do that. Associate the timer with
what the thread is doing, not with the thread.
DS
Yes, instead of having thread-specific timers, have any number of
generic timers.
cf. the POSIX.1-2001 functions setitimer(2) and getitimer(2),
or the POSIX.1-2008 functions timer_settime(2) and timer_gettime(2.
--
__Pascal Bourguignon__
You can store these values in thread specific variable and use it .
I didnt quite understand what you meant by "what the thread is doing"
Vs with the thread. Can you pls elaborate.
> I didnt quite understand what you meant by "what the thread is doing"
> Vs with the thread. Can you pls elaborate.
Okay, let's start with a simple question -- why would anyone want a
thread-specific timer? What possible function could it serve? Whatever
it is that you want to impose a timeout on, why associate the timer
with a thread?
It makes no sense to say "whatever this thread happens to be doing, I
want it to timeout in X time".
It does make sense to say "I need X to happen in Y time, unless Z",
but what does that have to do with any particular thread?
DS
> Okay, let's start with a simple question -- why would anyone want a
> thread-specific timer? What possible function could it serve? Whatever
> it is that you want to impose a timeout on, why associate the timer
> with a thread?
>
> It makes no sense to say "whatever this thread happens to be doing, I
> want it to timeout in X time".
I agree with you that most of the time it wouldn't make sense.
This is a bit of a corner case, but it's possible to set up posix timers
to use various clock sources. If you set the timer to use a per-thread
cpu-time clock, then this allows you to trigger a timer to fire in X
amount of runtime.
This can be useful if what you care about is runtime rather than actual
wall clock time.
Chris
Hi Chris,
Yes i am not interested in wall clock time, but needed a timer for X
amount of runtime, which can be different for different thread of my
app.
>If you set the timer to use a per-thread
>cpu-time clock, then this allows you to trigger a timer to fire in X
>amount of runtime.
So how does one use the per-thread cpu-time clock ?