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

Discussion in 'C Programming' started by liu yang, Jul 28, 2008.

  1. liu yang

    liu yang Guest

    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.
     
    liu yang, Jul 28, 2008
    #1
    1. Advertising

  2. Kenny McCormack, Jul 28, 2008
    #2
    1. Advertising

  3. On 28 Jul, 07:56, liu yang <> wrote:

    > 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
     
    Nick Keighley, Jul 28, 2008
    #3
  4. liu yang <> writes:
    > 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) <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"
     
    Keith Thompson, Jul 28, 2008
    #4
  5. On 28 Jul 2008 at 6:56, liu yang wrote:
    > 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.
     
    Antoninus Twink, Jul 28, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?S01aX3N0YXRl?=

    Quick one - Is SESSION per browser instance or per IP Address?

    =?Utf-8?B?S01aX3N0YXRl?=, Apr 4, 2006, in forum: ASP .Net
    Replies:
    7
    Views:
    5,949
    gerry
    Apr 10, 2006
  2. Razvan
    Replies:
    1
    Views:
    443
    tony vee
    Sep 10, 2004
  3. Replies:
    5
    Views:
    2,634
  4. Replies:
    0
    Views:
    372
  5. zxo102
    Replies:
    5
    Views:
    402
    zxo102
    Aug 15, 2006
Loading...

Share This Page