Rafi Cohen wrote:
Hi, I need some advice implementing timers in a multithread aplication on linux (suse 9.3, kernel 2.6.11).
The application is written in C.
At first, I chose to use alarm() with a handler for SIGALRM, but after some tests I concluded tht it's not wise to use this in a multithread application, since it seems that each call to alarm() affects or even cancels the previous one, even though the previous call was in another thread. Do I miss here something? may this still be used in a multithread application? Yes, I know about getitimer and setitimer, but I do not understand how to adjust the timer, for example if I want a timer of 20 seconds. If this is the solution you suggest, please provide an example that shows how to use those functions.
Generally, any advise concerning this issue will be most appreciated.
Thanks, Rafi.

POSIX timers are per proccess not per thread.

setitimer will still give you one timer per process (OK, actually it will give you 3 timers but each runs in a different time domain and you are only interested in wall clock timer it seems so you still have only one).

To do what you want you need to write you on timers heap implmentation based on the single timer you have. You are advised to use a special "timers" thread for this that blocks with sigwait() for SIGALRM and mask out all other threads from receving SIGALRM if you want anything near sane application.

Generally threads and signals mix badly and in POSIX a timer is implmented as a signal :-(

Gilad

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to