tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
How to wait on cv_timedwait() correctly
Hello,
I think I have found a PR relating to my question:
http://gnats.netbsd.org/38554
I am implementing a semaphore system for applications. To wait on a
semaphore to become ready, it does basically this:
do
{
khs->khs_waiters++;
error = cv_timedwait_sig(&khs->khs_cv,
&khs->khs_interlock, mstohz((flags & SEM_RELATIVE_TIMEOUT) ? timeout :
0));
khs->khs_waiters--;
[...]
} while (khs->khs_count - count < 0);
I have seen that cv_signal() on a CV unblocks all threads waiting on
it, instead of just one. That this could happen is briefly mentioned
in condvar(9).
I think the problem is that when cv_timedwait_sig() is called
repeatedly, the original timeout is used again and again, adding up to
an unpredictable amount of time.
If that is the case, how can it be solved best? Is
cv_timedwaitbt_sig() suitable? Or should one track sleep and wakeup
times and calculate a new timeout each time?
Thanks,
Stephan
Home |
Main Index |
Thread Index |
Old Index