================线程1
pthread_mutex_lock(&mutex);
do
{
fun();//this fun will cost a long time, maybe 1-2 second
gettimeofday(&now, NULL);
outtime.tv_sec = now.tv_sec + 5;
outtime.tv_nsec = now.tv_usec * 1000;
int ret = pthread_cond_timedwait(&cond, &mutex, &outtime);
} while((!predicate && ret != ETIMEDOUT)
pthread_mutex_unlock(&mutex);
===========================线程2
pthread_mutex_lock(&mutex);
predicate = true;
pthread_cond_signal(&cond);
pthread_mutex_unlock(&mutex);
如果thread2在thread1的fun()过程中发送了信号,没有pthread_cond_timedwait,当fun()调用返回时,thread1中的phread_cond_timedwait仍然可以得到thread2之前发送过的信号吗?我们可以在 while() 中调用 pthread_cond_timedwait 之前的耗时乐趣吗?