tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: How to wait on cv_timedwait() correctly



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


Home | Main Index | Thread Index | Old Index