void wait(int timeInMs) { struct timespec timeToWait; timeToWait.tv_sec = 5; timeToWait.tv_nsec = timeInMs*1000; int rt; pthread_mutex_lock(&am
Considering you are using timespec, and your goal isn't to synchronize but to wait I'd suggest nanosleep.
#include . . . struct timespec remain; remain.tv_sec = 5; remain.tv_nsec = timeInMs * 1000; do { if ( nanosleep( &remain, &remain ) == 0 || errno != EINTR ) { break; } } while ( 1 ); . . .