timers with pthread

Discussion in 'C' started by bsushma, Sep 3, 2010.

  1. bsushma

    bsushma New Member

    Joined:
    Sep 3, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Can somebody provide me example of starting and stop an userdefined timer on PTHREAD concepts ?

    Basically, like this. one thread started TIMER1, now other thread on TIMER1 with value x need to stop the TIMER1 and start TIMER2.

    Please help me.

    for ex:

    In the following program, can somebody suggest me to start another THREAD and cancel the the timer which i started currently when it is delayed for 3secs.

    Code:
    struct timeval tv; 
    
    int set_timer(struct timeval &tv,time_t sec)
    {
     gettimeofdat(&tv,NULL);
     tv.tv_sec += sec;
     return 1;
    }
    
    void* timer(void* arg)
    {
       set_timer(tv,5);
    }
      
    int main(int argc, char* argv[])  
     {  
     
    pthread_create (&thread_id, NULL,&timer,NULL);
    pthread_join(&thread_id);
    
    }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice