void wait(int timeInMs)
{
struct timespec timeToWait;
timeToWait.tv_sec = 5;
timeToWait.tv_nsec = timeInMs*1000;
int rt;
pthread_mutex_lock(&am
That code doesn't sleep, it checks a condition for a while. As you are not probably setting cond ok it just returns immediately.
If you are not willing to synchronize threads around a signal then pthread_cond _wait is not what you need. Check here how condition variables work.
if you want to sleep with seconds precision use sleep
If you want to sleep with microseconds precision use select with timevals.