2016-03-31 60 views
0

等待狀態變量在linux等待條件變量時會發生什麼情況時condition_timed_wiat()時間逝去時會發生什麼情況時condition_timed_wiat時間流逝在linux

struct timeval tv; 
    struct timespec ts; 

    gettimeofday(&tv, NULL); 
    ts.tv_sec = time(NULL) + timeInMs/1000; 
    ts.tv_nsec = tv.tv_usec * 1000 + 1000 * 1000 * (timeInMs % 1000); 
    ts.tv_sec += ts.tv_nsec/(1000 * 1000 * 1000); 
    ts.tv_nsec %= (1000 * 1000 * 1000); 

    n = pthread_cond_timedwait(&condition, &mutex, &ts); 

回答

0

該函數返回ETIMEDOUT(它是一個非零值)和該互斥鎖未鎖定。