????????pthread_cond_timedwait???????????£?

#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>
#include <pthread.h>
#include <errno.h>
 
static pthread_t thread;
static pthread_cond_t cond;
static pthread_mutex_t mutex;
static int flag = 1;
 
void * thr_fn(void * arg)
{
  struct timeval now;
  struct timespec outtime;
  pthread_mutex_lock(&mutex);
  while (flag) {
    printf("***** ");
    gettimeofday(&now?? NULL);
    outtime.tv_sec = now.tv_sec + 5;
    outtime.tv_nsec = now.tv_usec * 1000;
    pthread_cond_timedwait(&cond?? &mutex?? &outtime);
  }
  pthread_mutex_unlock(&mutex);
  printf("cond thread exit ");
}
 
int main(void)
{
  pthread_mutex_init(&mutex?? NULL);
  pthread_cond_init(&cond?? NULL);
  if (0 != pthread_create(&thread?? NULL?? thr_fn?? NULL)) {
    printf("error when create pthread??%d "?? errno);
    return 1;
  }
  char c ;
  while ((c = getchar()) != 'q');
  printf("Now terminate the thread! ");

  pthread_mutex_lock(&mutex);
  flag = 0;
  pthread_cond_signal(&cond);
  pthread_mutex_unlock(&mutex);
  printf("Wait for thread to exit ");
  pthread_join(thread?? NULL);
  printf("Bye ");
  return 0;
}
 


????pthread_cond_timedwait()?????????????ú??????????????cond?????????????????pthread_cond_broadcast() or pthread_cond_signal()????

??????pthread_cond_timedwait()???????????????????????????mutex??????pthread_cond_timedwait()???mutex???С?????????ж?????????????????????????????????ζ??????????????????????????????????In this case?? atomically means with respect to the mutex andthe condition variable and other access by threads to those objectsthrough the pthread condition variable interfaces.??

???????????????????????????????????????????????????????????????mutex???????????mutex??????EPERM?????????ú??????????mutex?????????????????

???????????????abstime???????????????????????????????????ETIMEDOUT?????????????????????????????????

????????????????????????????????????????????????????????????????????????????????????????????????????????????gettimeofday()???timeval???塣