void wait(int timeInMs) { struct timespec timeToWait; timeToWait.tv_sec = 5; timeToWait.tv_nsec = timeInMs*1000; int rt; pthread_mutex_lock(&am
The pthread_cond_timedwait function takes an absolute time, not a relative time. It takes the time you want to stop waiting, not how long you want to wait.
pthread_cond_timedwait