pthread_cond_init(&cond, NULL);
pthread_mutex_init (&mutex, NULL);
pthread_mutex_lock (&mutex);
struct timespec timeout;
/*
struct timeval now;
gettimeofday(&now);
timeout.tv_sec = now.tv_sec+2;
timeout.tv_nsec = now.tv_usec * 1000;
*/
timeout.tv_sec = time(NULL)+2; //Wait for 1 second, Must
timeout.tv_nsec = 0;
if(pthread_cond_timedwait(&cond, &mutex, &timeout)!=ETIMEDOUT)
{
}
pthread_mutex_lock (&mutex);
pthread_cond_signal (&cond);
pthread_mutex_unlock (&mutex);