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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • liu yang

    #1

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

    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.


  • Kenny McCormack

    #2
    Re: how to implement per-thread timer in a multi-thread program?

    In article <8f9c23f5-dee6-4786-a94e-fc8c38a1487b@h1 7g2000prg.googl egroups.com>,
    liu yang <liudows2@gmail .comwrote:
    >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.
    Off topic. Not portable. Cant discuss it here. Blah, blah, blah.

    --
    Useful clc-related links:





    Comment

    • Nick Keighley

      #3
      Re: how to implement per-thread timer in a multi-thread program?

      On 28 Jul, 07:56, liu yang <liudo...@gmail .comwrote:
      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

      Comment

      • Keith Thompson

        #4
        Re: how to implement per-thread timer in a multi-thread program?

        liu yang <liudows2@gmail .comwrites:
        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.programmin g.threads.

        --
        Keith Thompson (The_Other_Keit h) kst-u@mib.org <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"

        Comment

        • Antoninus Twink

          #5
          Re: how to implement per-thread timer in a multi-thread program?

          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.

          Comment

          Working...