linux 定時器

     有些東西雖然簡單,但時間長了 不記錄 再用總會多花時間... 記錄下

    

void AlarmFunc(int signo)
{
    pthread_mutex_lock(&g_mutexLock);
    KALDI_LOG << "the feature of " << g_tempEnrollIvectors.size() << "speaker are written into the file";
    for (size_t i = 0; i < g_tempEnrollIvectors.size(); i++)
    {
        g_ivectorWriter.Write(g_tempEnrollIvectors[i].first, *(g_tempEnrollIvectors[i].second));
    }
    g_tempEnrollIvectors.clear();
    pthread_mutex_unlock(&g_mutexLock);
}


/// set timer 5秒執行一次 AlarmFunc 函數
struct itimerval tick;
signal(SIGALRM, AlarmFunc);
memset(&tick, 0, sizeof(tick));
//Timeout to run first time
tick.it_value.tv_sec = 1;
tick.it_value.tv_usec = 0;
//After first, the Interval time for clock
tick.it_interval.tv_sec = 5;
tick.it_interval.tv_usec = 0;
if (setitimer(ITIMER_REAL, &tick, NULL) < 0)
return "Init fail,Set timer failed!";


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章