Connecting Tech Pros Worldwide Help | Site Map

how to implement per-thread timer in a multi-thread program?

liu yang
Guest
 
Posts: n/a
#1: Jul 28 '08
I want to build a timer for each thread, and the timer must be thread-
safe. How to do that?

My environment is Linux and Pthread.

Thanks.


Kenny McCormack
Guest
 
Posts: n/a
#2: Jul 28 '08

re: how to implement per-thread timer in a multi-thread program?


In article <8f9c23f5-dee6-4786-a94e-fc8c38a1487b@h17g2000prg.googlegroups.com>,
liu yang <liudows2@gmail.comwrote:
Quote:
>I want to build a timer for each thread, and the timer must be thread-
>safe. How to do that?
>
>My environment is Linux and Pthread.
>
>Thanks.
Off topic. Not portable. Cant discuss it here. Blah, blah, blah.

--
Useful clc-related links:

http://en.wikipedia.org/wiki/Aspergers
http://en.wikipedia.org/wiki/Clique
http://en.wikipedia.org/wiki/C_programming_language

Nick Keighley
Guest
 
Posts: n/a
#3: Jul 28 '08

re: how to implement per-thread timer in a multi-thread program?


On 28 Jul, 07:56, liu yang <liudo...@gmail.comwrote:
Quote:
I want to build a timer for each thread, and the timer must be thread-
safe. How to do that?
>
My environment is Linux and Pthread.
comp.lang.c is for the discussion of standard C (as defined by the ISO
standard). Consequently it does not discuss timers or threads. You
ned to look in a thread or platform (OS) specific group for more
information.

--
Nick Keighley

Keith Thompson
Guest
 
Posts: n/a
#4: Jul 28 '08

re: how to implement per-thread timer in a multi-thread program?


liu yang <liudows2@gmail.comwrites:
Quote:
I want to build a timer for each thread, and the timer must be thread-
safe. How to do that?
>
My environment is Linux and Pthread.
Try a Linux newsgroup or comp.programming.threads.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Antoninus Twink
Guest
 
Posts: n/a
#5: Jul 28 '08

re: how to implement per-thread timer in a multi-thread program?


On 28 Jul 2008 at 6:56, liu yang wrote:
Quote:
I want to build a timer for each thread, and the timer must be thread-
safe. How to do that?
>
My environment is Linux and Pthread.
Unfortunately, there is no way to get POSIX alarms to signal a calling
thread specifically. So you'll need to do some manual coding around it.

You can set up a thread to deal with the alarms. It blocks all signals
except that it sets up a handler for SIGALRM, then enters a sigwait()
loop.

When another thread wants to receive that alarm, it sets up a handler
for SIGUSR1 (say), and calls a function you provide that registers that
thread with your waiting thread.

When the process is sent a SIGALRM, the waiting thread returns from
sigwait(), works out which thread it should send the alarm to, and sends
a SIGUSR1 to that thread.

Of course you need to be quite careful to keep track of which thread
asked for an alarm at what time, and reset the alarm when necessary.

Closed Thread