Skip to content

Conversation

joboet
Copy link
Contributor

@joboet joboet commented Aug 16, 2022

Futexes greatly simplify the creation of synchronization primitives (see std's mutex). They are here implemented by using a hashmap, in which the handles to waiting threads are stored, keyed with the address of the futex they are waiting on.

I prioritised readability over performance in this PR, faster implementations would use finer grained locking and would not need to allocate the queues. It should be performant enough for most purposes however.

Copy link
Member

@mkroening mkroening left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!
Thanks a lot for your effort of migrating to the generic futex-based impls in std. :)

@mkroening mkroening requested a review from stlankes August 23, 2022 09:50
@mkroening
Copy link
Member

bors try

bors bot added a commit that referenced this pull request Aug 29, 2022
@bors
Copy link
Contributor

bors bot commented Aug 29, 2022

Copy link
Contributor

@stlankes stlankes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excuse me for the late review. I was ill. Like @mkroening, I have the same question __sys_futex_wait.

The rest looks good for me! Thank you for your great support.

@joboet
Copy link
Contributor Author

joboet commented Sep 3, 2022

I've now clarified the timeout behaviour in the documentation. Also, futex_wait now does not return spuriously in order to match the behaviour on modern Linux systems.

Copy link
Member

@mkroening mkroening left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, @joboet! :)

bors r+

@bors
Copy link
Contributor

bors bot commented Sep 4, 2022

@bors bors bot merged commit 618b0d4 into hermit-os:master Sep 4, 2022
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 9, 2022
Use futex-based locks and thread parker on Hermit

[Hermit now has futex syscalls](hermit-os/kernel#534), which means Hermit can share the well-tested and performant locks and thread parker used on Linux.

Ping `@mkroening,` `@stlankes`
r? `@m-ou-se`
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

Successfully merging this pull request may close these issues.

3 participants