Skip to content

lock: change locking to a mutex#13

Open
mkalte666 wants to merge 1 commit intoGregoireHENRY:mainfrom
mkalte666:lock-mutex
Open

lock: change locking to a mutex#13
mkalte666 wants to merge 1 commit intoGregoireHENRY:mainfrom
mkalte666:lock-mutex

Conversation

@mkalte666
Copy link
Copy Markdown

@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
Copy Markdown
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