/* * gcc -Wall -O2 -o cvtest cvtest.c -lpthread */ #include #include #include #include #include #include #include #include #define DISK_UTIL_MSEC 250 struct d { pthread_mutex_t *lock; pthread_cond_t *cond; }; static void *thread(void *data) { struct d *d = data; struct timespec ts; struct timeval tv; int ret; gettimeofday(&tv, NULL); ts.tv_sec = tv.tv_sec + 1; ts.tv_nsec = 1000000000ULL; printf("will wait\n"); pthread_mutex_lock(d->lock); ret = pthread_cond_timedwait(d->cond, d->lock, &ts); pthread_mutex_unlock(d->lock); printf("done wait %d\n", ret); return NULL; } int main(int argc, char *argv[]) { pthread_cond_t cond; pthread_mutex_t lock; pthread_t pthread; struct d d; void *ret; pthread_cond_init(&cond, NULL); pthread_mutex_init(&lock, NULL); d.lock = &lock; d.cond = &cond; pthread_create(&pthread, NULL, thread, &d); pthread_join(pthread, &ret); return 0; }