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

lock: change locking to a mutex #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mkalte666
Copy link

@mkalte666 mkalte666 commented Apr 26, 2023

I suggest changing the locking mechanism behind SpiceLock to a mutex.

Mutexes have the advantage that they allow for blocking waits natively. These are typically handled by some external sync mechanism. Thusly, threads will be put to sleep by the OS until the other place has unlocked it.
The old atomic-bool solution required a busy-wait to achieve this.

This changed implementation has the disadvantage that it requires rustc version >= 1.70.0 which, as of commiting this, still is in beta (it is stabilized however, so its just a small wait, not an indeterminate one!) . However OnceLock avoids having to pull in once_cell or lazy_static as dependencies. So i think its best to wait until june to merge this.

Have a great week!

EDIT: Oh and since you did the original legwork, what are your thoughts on this @mclrc ?

~mkalte

Mutexes have the advantage that they allow for blocking waits natively.
These are typically handled by some external sync mechanism.
Thusly, threads will be put to sleep by the OS until the other place has
unlocked it.
The old atomic-bool solution required a busy-wait to achieve this.

This changed implementation has the disadvantage that it requires rustc
version >= 1.70.0 which, as of commiting this, still is in beta.
However OnceLock avoids having to pull in once_cell or lazy_static as
dependencies. So i think its best to wait until june and then merge
this.
@mclrc
Copy link
Contributor

mclrc commented Oct 16, 2023

Sorry for the super late response, I missed the notification somehow. I don't really know a lot about the lower level details, but it sounds like it makes sense! And by now everything needed is stable, right?

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.

2 participants