timer sanity check - Unix

This is a discussion on timer sanity check - Unix ; Hi all, I need to implement a simple timer, where I could say it to call a certain function at a certain time. I have to be able to set as many of such timer events as I want. Aside ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: timer sanity check

  1. timer sanity check

    Hi all,

    I need to implement a simple timer, where I could say it to call a
    certain function at a certain time. I have to be able to set as many
    of such timer events as I want. Aside of calling the function, I
    don't want any other side-effects on the rest of the system.

    Is it a good idea to build this on top of setitimer()? What would be
    the implications with interrupted system calls, etc.?

    Thanks for any advice,

    Arkadiy

  2. Re: timer sanity check

    On Nov 29, 7:52 am, Arkadiy wrote:
    > Hi all,
    >
    > I need to implement a simple timer, where I could say it to call a
    > certain function at a certain time. I have to be able to set as many
    > of such timer events as I want. Aside of calling the function, I
    > don't want any other side-effects on the rest of the system.
    >
    > Is it a good idea to build this on top of setitimer()?


    Seems reasonable to me. Since there's only one timer, you'll have to
    have it handle all the events, recalculating timeouts if an event is
    added or removed, but that's not so hard. You will also have to be
    aware of what is and isn't permissible inside a signal handler (your
    sigaction(2) man page may have a list), as well as the usual concerns
    if your handler will modify any global state.

    > What would be
    > the implications with interrupted system calls, etc.?


    If you use the SA_RESTART flag to sigaction, you should not have
    system calls failing with EINTR. You may have "partial completions";
    for example, if read(fd, buf, 100) is called, but a signal arrives
    after only 50 bytes have been read, read() will return 50. write(),
    select(), and sleep() are some other examples where this sort of thing
    can happen. So you need to be very diligent about checking return
    values, but of course you should be anyway.


+ Reply to Thread