Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document the semaphore implementation better #2

Open
bugaevc opened this issue Dec 14, 2020 · 0 comments
Open

Document the semaphore implementation better #2

bugaevc opened this issue Dec 14, 2020 · 0 comments

Comments

@bugaevc
Copy link
Owner

bugaevc commented Dec 14, 2020

The semaphore implementation is rather complicated. The trick a mutex uses to avoid losing wakeups is already tricky enough ("futexes are tricky!") that it took me a long time to understand; the semaphore is far more complex & trickier. It needs to wake multiple threads simultaneously, and the responsibility for waking them is split between threads calling up() and threads calling down() (waking up anyone in down() is very unusual!), and it oftentimes sets the need_to_wake_bit even when there are remaining slots. This all needs more docs/comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant