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

Use async mutex instead of std mutex #7

Merged
merged 1 commit into from
Dec 2, 2021
Merged

Use async mutex instead of std mutex #7

merged 1 commit into from
Dec 2, 2021

Conversation

lamafab
Copy link
Contributor

@lamafab lamafab commented Dec 2, 2021

Uses the async Mutex, which locks per task rather than per thread.

@ironoa
Copy link
Contributor

ironoa commented Dec 2, 2021

Fine for me, would be very interesting if you could add a Rust documentation link

@lamafab
Copy link
Contributor Author

lamafab commented Dec 2, 2021

Fine for me, would be very interesting if you could add a Rust documentation link

Async Rust has some edge cases that aren't entirely clear at first sight. rust-lang/rust#71072 My vscode Rust plugin automatically added the std Mutex import and it slipped my mind that I need to explicitly use the async version one.

You need to be aware that ordinary mutexes insist on being unlocked on the same thread that locked them; and that executors move tasks from one thread to another; and that the solution is not to make ordinary mutexes more complex but to create a new mutex type altogether. These make sense in hindsight, but I'll bet that they leap to mind only for a small group of elite users.

I guess my initial comment about "nothing major" was not quite correct :)

@lamafab lamafab merged commit 81fe5f7 into master Dec 2, 2021
@ironoa ironoa deleted the async-mutex branch December 2, 2021 14:54
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