|
Home > Archive > Unix Programming > May 2004 > Best way to implement a resettable timer.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Best way to implement a resettable timer.
|
|
| RJGraham 2004-05-30, 10:29 am |
| What's the best way to to implement a resettable timer, kind of like a
watchdog timer that can be reset.
I want to be able to start a timer to wait on an event, and either
timeout, or reset the timer to wait on the next event. The idea here is
to detect timeouts in my application.
select() would seem to be the obvious choice, but I need a file
descriptor and my timeouts are not necessarily tied to file i/o (or
other I/O).
Is it acceptable to open a file descriptor on '/dev/null' and FD_SET it
to break out of a select() wait for my timer?
Otherwise, how can I create a fd to use with select that is not tied to
file I/O, that I can set/reset ?
-Randy
| |
| Måns Rullgård 2004-05-30, 10:29 am |
| RJGraham <null@null.com> writes:
> What's the best way to to implement a resettable timer, kind of like a
> watchdog timer that can be reset.
>
> I want to be able to start a timer to wait on an event, and either
> timeout, or reset the timer to wait on the next event. The idea here
> is to detect timeouts in my application.
>
> select() would seem to be the obvious choice, but I need a file
> descriptor and my timeouts are not necessarily tied to file i/o (or
> other I/O).
>
> Is it acceptable to open a file descriptor on '/dev/null' and FD_SET
> it to break out of a select() wait for my timer?
>
> Otherwise, how can I create a fd to use with select that is not tied
> to file I/O, that I can set/reset ?
Create a pipe() and select() on the reading end. When you want to
reset you simply write one byte to the writing end of the pipe.
--
Måns Rullgård
mru@kth.se
| |
| RJGraham 2004-05-30, 10:29 am |
| Måns Rullgård wrote:
> RJGraham <null@null.com> writes:
>
>
>
>
> Create a pipe() and select() on the reading end. When you want to
> reset you simply write one byte to the writing end of the pipe.
>
Ok, that'll work.
Thanks for your help.
-Randy
| |
| Barry Margolin 2004-05-30, 10:29 am |
| In article <xKudnSWVeor1livdRVn_vQ@giganews.com>,
RJGraham <null@null.com> wrote:
> What's the best way to to implement a resettable timer, kind of like a
> watchdog timer that can be reset.
>
> I want to be able to start a timer to wait on an event, and either
> timeout, or reset the timer to wait on the next event. The idea here is
> to detect timeouts in my application.
Use alarm() to schedule a SIGALRM signal. Since there's only one such
timer per process, every time you reschedule it the previous one will be
reset.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
|
|
|
|
|