Re: How to wait on cv_timedwait() correctly
Johnny Billquist <[email protected]>
| Newsgroups | gmane.os.netbsd.devel.kernel |
|---|---|
| Organization | SoftJAR AB |
| Message-ID | <[email protected]> |
Why not use cv_timedwaitbt_sig() in that case? It updates the time
argument based on amount of time passed.
But I don't think cv_signal() unblocks all. Not sure why you think that.
That would be cv_broadcast().
Johnny
On 2025-01-30 15:37, Stephan wrote:
> 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
--
Johnny Billquist || "I'm on a bus
|| on a psychedelic trip
email: [email protected] || Reading murder books
pdp is alive! || tryin' to stay hip" - B. Idol