Timer in C - Unix

This is a discussion on Timer in C - Unix ; Hello, I'm referring to a thread that I started some days ago on comp.lang.c: http://groups.google.it/group/comp.l...7684b31a81dcd2 . I read various documentation on the Internet, but I think neither ualarm() or setitimer() satisfy me completely. What I need to do, in fact, ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Timer in C

  1. Timer in C

    Hello, I'm referring to a thread that I started some days ago on
    comp.lang.c:
    http://groups.google.it/group/comp.l...7684b31a81dcd2.
    I read various documentation on the Internet, but I think neither
    ualarm() or setitimer() satisfy me completely. What I need to do, in
    fact, is create a series of different timers inside a process, like
    timer objects (of course, not true objects, but conceptually it's like
    an object), each one referrable, with some kind of reference (a
    pointer). Then, under certain conditions, I need to reset one or more
    of them (that's why I need some way to refer to every single timer
    specificly), to prevent them sending the SIGALARM (any other kind of
    signal they might send), because otherwise I line in the console is
    written with 'puts("Alarm: The timer x has expired")' or printf(), at
    each expiration of each timer.
    From what I've read, both ualarm() and setitimer() (the first is
    actually based on the second) allows you to manage one single global
    timer, the one of the caller process...
    So, in my opinion (correct me if I'm wrong, my knownledge of C is
    quite limited) the only 2 ways to do this would be:
    1 - Create a series of threads, one for each timer I want to create,
    and inside each thread call ualarm(), to set the per-thread timer...Or
    maybe I'd need to create child processes, instead of threads?
    2 - Use a series of timer_create(), without the need to create any per-
    timer thread...
    Is there a simpler and more lightweight way to do this?
    Thanks a lot

  2. Re: Timer in C

    Alexander Mahone writes:
    >Hello, I'm referring to a thread that I started some days ago on
    >comp.lang.c:
    >http://groups.google.it/group/comp.l...7684b31a81dcd2.
    >I read various documentation on the Internet, but I think neither
    >ualarm() or setitimer() satisfy me completely. What I need to do, in
    >fact, is create a series of different timers inside a process, like
    >timer objects (of course, not true objects, but conceptually it's like
    >an object), each one referrable, with some kind of reference (a
    >pointer). Then, under certain conditions, I need to reset one or more
    >of them (that's why I need some way to refer to every single timer
    >specificly), to prevent them sending the SIGALARM (any other kind of
    >signal they might send), because otherwise I line in the console is
    >written with 'puts("Alarm: The timer x has expired")' or printf(), at
    >each expiration of each timer.
    >From what I've read, both ualarm() and setitimer() (the first is
    >actually based on the second) allows you to manage one single global
    >timer, the one of the caller process...
    >So, in my opinion (correct me if I'm wrong, my knownledge of C is
    >quite limited) the only 2 ways to do this would be:
    >1 - Create a series of threads, one for each timer I want to create,
    >and inside each thread call ualarm(), to set the per-thread timer...Or
    >maybe I'd need to create child processes, instead of threads?
    >2 - Use a series of timer_create(), without the need to create any per-
    >timer thread...
    >Is there a simpler and more lightweight way to do this?
    >Thanks a lot


    Link your "timer objects" into a sorted list (shortest wakeup first);
    Using a single thread, have it wait until the next wakeup, then deliver
    the timer (raise a signal, signal a condition variable, post a bit,
    whatever), delink the element and wait for the next wakeup.

    scott

  3. Re: Timer in C

    On Apr 28, 7:41*am, Alexander Mahone
    wrote:
    > Hello, I'm referring to a thread that I started some days ago on
    > comp.lang.c:http://groups.google.it/group/comp.l.../thread/f99fda....
    > I read various documentation on the Internet, but I think neither
    > ualarm() or setitimer() satisfy me completely. What I need to do, in
    > fact, is create a series of different timers inside a process, like
    > timer objects (of course, not true objects, but conceptually it's like
    > an object), each one referrable, with some kind of reference (a
    > pointer). Then, under certain conditions, I need to reset one or more
    > of them (that's why I need some way to refer to every single timer
    > specificly), to prevent them sending the SIGALARM (any other kind of
    > signal they might send), because otherwise I line in the console is
    > written with 'puts("Alarm: The timer x has expired")' or printf(), at
    > each expiration of each timer.
    > From what I've read, both ualarm() and setitimer() (the first is
    > actually based on the second) allows you to manage one single global
    > timer, the one of the caller process...
    > So, in my opinion (correct me if I'm wrong, my knownledge of C is
    > quite limited) the only 2 ways to do this would be:
    > 1 - Create a series of threads, one for each timer I want to create,
    > and inside each thread call ualarm(), to set the per-thread timer...Or
    > maybe I'd need to create child processes, instead of threads?
    > 2 - Use a series of timer_create(), without the need to create any per-
    > timer thread...
    > Is there a simpler and more lightweight way to do this?
    > Thanks a lot


    What does the program do while waiting for the timers to fire?
    Is this a GUI program?
    This is very easy to do if you are using the Xt toolkit.
    --
    Fred Kleinschmidt

  4. Re: Timer in C

    On 28 apr, 16:41, Alexander Mahone
    wrote:
    > Hello, I'm referring to a thread that I started some days ago on
    > comp.lang.c:http://groups.google.it/group/comp.l.../thread/f99fda....
    > I read various documentation on the Internet, but I think neither
    > ualarm() or setitimer() satisfy me completely. What I need to do, in
    > fact, is create a series of different timers inside a process, like
    > timer objects (of course, not true objects, but conceptually it's like
    > an object), each one referrable, with some kind of reference (a
    > pointer). Then, under certain conditions, I need to reset one or more
    > of them (that's why I need some way to refer to every single timer
    > specificly), to prevent them sending the SIGALARM (any other kind of
    > signal they might send), because otherwise I line in the console is
    > written with 'puts("Alarm: The timer x has expired")' or printf(), at
    > each expiration of each timer.
    > From what I've read, both ualarm() and setitimer() (the first is
    > actually based on the second) allows you to manage one single global
    > timer, the one of the caller process...
    > So, in my opinion (correct me if I'm wrong, my knownledge of C is
    > quite limited) the only 2 ways to do this would be:
    > 1 - Create a series of threads, one for each timer I want to create,
    > and inside each thread call ualarm(), to set the per-thread timer...Or
    > maybe I'd need to create child processes, instead of threads?
    > 2 - Use a series of timer_create(), without the need to create any per-
    > timer thread...
    > Is there a simpler and more lightweight way to do this?
    > Thanks a lot


    maybe you could use select.h, poll.h, .. or some other though i don't
    know which one is meanth for windows, .. the above only work in linux
    if i recall well.

+ Reply to Thread