Re: How to wait on cv_timedwait() correctly

Jason Thorpe <[email protected]>
Newsgroups gmane.os.netbsd.devel.kernel
Message-ID <[email protected]>

> On Jan 30, 2025, at 6:37 AM, Stephan <[email protected]> wrote:
> 
> 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).

cv_signal() unblocks only a single thread.  The implementation is in kern/kern_condvar.c, and it’s very clear and obvious how it works.  I assume what you’re referring to is the warning about spurious wakes, which is in the description if cv_wait(), and is a completely separate issue.

> 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?

I think cv_timedwaitbt_sig() should do the job here.

-- thorpej
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.