pthread_cond_timedwait returning immediately

后端 未结 4 1748
礼貌的吻别
礼貌的吻别 2021-02-15 15:23

I\'m having a strange problem. I have the following code:

    dbg(\"condwait: timeout = %d, %d\\n\", 
        abs_timeout->tv_sec, abs_timeout->tv_nsec);
          


        
4条回答
  •  野的像风
    2021-02-15 15:53

    As already in other answers mentioned you have to use the absolute time. Since C11 you can use timespec_get().

    struct timespec time;
    timespec_get(&time, TIME_UTC);
    time.tv_sec += 5;
    
    pthread_cond_timedwait(&cond, &mutex, &time);
    

提交回复
热议问题