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

don't busy wait in SemaphoreGuard::acquire_arc #42

Merged
merged 3 commits into from
May 27, 2023

Conversation

SNCPlay42
Copy link
Contributor

Fixes #41

I also added a test for this for each of Mutex/RwLock/Semaphore. The existing tests almost all use different threads when tasks contend for locks so they wouldn't catch this.

tests/mutex.rs Outdated
future::block_on(async {
let m = Mutex::new(());
let _g = m.try_lock().unwrap();
assert!(future::poll_once(m.lock()).await.is_none());
Copy link
Member

Choose a reason for hiding this comment

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

This test should also make sure that the future wakes back up once the other lock is dropped. Ditto for all of the others.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does it suffice to check that the future now returns Ready or do you want to check that the Waker was triggered? I can do the latter but I think I'd need to add waker-fn as a dev dependency to do it cleanly.

Copy link
Member

Choose a reason for hiding this comment

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

Doing both would be nice. It's fine to add waker-fn as a dev dependency, since it's already brought in via futures-lite.

Copy link
Member

@notgull notgull left a comment

Choose a reason for hiding this comment

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

Thanks!

@notgull notgull merged commit 6bac58a into smol-rs:master May 27, 2023
@notgull notgull mentioned this pull request Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

SemaphoreGuard::acquire_arc busy waits since 2.7.0/#34
2 participants