pthread_cond_timedwait returning immediately

后端 未结 4 1750
礼貌的吻别
礼貌的吻别 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:52

    Overflow in timespec is usually the culprit for weird timeouts.
    Check for EINVAL:

    void timespec_add(struct timespec* a, struct timespec* b, struct timespec* out)
    {
        time_t sec = a->tv_sec + b->tv_sec;
        long nsec = a->tv_nsec + b->tv_nsec;
    
        sec += nsec / 1000000000L;
        nsec = nsec % 1000000000L;
    
        out->tv_sec = sec;
        out->tv_nsec = nsec;
    }
    

提交回复
热议问题