Problem in Timers and signal

前端 未结 4 1987
别跟我提以往
别跟我提以往 2020-12-06 03:35

I have implemented a POSIX timer using timer_create( ) API, and this will generate SIGUSR1 when the timer expires for which i have put a handler code. Now the problem is, if

4条回答
  •  心在旅途
    2020-12-06 03:55

    The question is whether you really need to use signals. You may think of using callback that will be called when the timer expires:

    void cbf(union sigval);
    struct sigevent sev;
    timer_t timer;
    
    sev.sigev_notify = SIGEV_THREAD;
    sev.sigev_notify_function = cbf; //this function will be called when timer expires
    sev.sigev_value.sival_ptr = (void*) arg;//this argument will be passed to cbf
    timer_create(CLOCK_MONOTONIC, &sev, &timer);
    

    The callback function will be called in a new thread.

提交回复
热议问题