Re: How to wait on cv_timedwait() correctly

Stephan <[email protected]>
Newsgroups gmane.os.netbsd.devel.kernel
Message-ID <CABZpUSUPSn6Y8mFDqQxkSJeMap5icJ8t11dLxGk6-YmXApofvw@mail.gmail.com>
Hello Taylor,

thank you for your detailed response and for sharing so much knowledge.

I have a much better understanding now and I am confident that I can
implement a proper solution.

I think some of the details you shared are even beyond of which I can
understand, and I know that other parts of the kernel are much more
sophisticated than just some syscalls that I am working on.


> By the way: Does khs->khs_waiters exist only as a micro-optimization
> for the wakeup path?
>
>         if (__predict_false(khs->khs_waiters))
>                 cv_signal/broadcast(cv);

The khs_waiters field of the structure is important when a semaphore is deleted.

All threads waiting on it are notified and check the state of the semaphore.

If it was deleted, all threads unlock the mutex and just go away
except the last one, which needs to call a function bringing the
semaphore back to a free state.

The whole code can be found here:

https://github.com/stephanwib/src/blob/trunk/sys/kern/uipc_hsem.c

This API is very close to what is found on BeOS/Haiku and is of course
part of my effort to make Haiku software run on NetBSD.


Stephan
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.