Thanks to @john Bollinger! His suggestion got me on track.
I have created global variable:
pthread_cond_t condition;
Initialized this one with defaults:
r = pthread_cond_init(&condition, NULL);
And went to sleep by this:
rt = pthread_cond_timedwait(&condition, &lock, &ts);
Where lock
is a global lockfile (which I was already using anyways):
pthread_mutex_t lock;
And ts
is of struct timespec ts;
Because pthread_cond_timedwait
does not wait for seconds to pass, instead until a specified time has come I just added the sleeping time: ts.tv_sec += waitSecs;
In the other thread it was very easy. Just inform the waiting thread:
pthread_cond_signal(&condition);
while the lock is blocked by the sending thread.
Works like a charm! Thanks again!