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

Fix unsoundness #6

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

Conversation

DzenanJupic
Copy link

Closes #5

self
.value
.try_insert(value)
.map_err(|_| ())

Choose a reason for hiding this comment

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

Why mapping the error to a unit and not just expecting/unwrapping the original error? Just curious.

Copy link
Author

Choose a reason for hiding this comment

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

The error in this case is the value that we passed to try_insert in the line above. expect as well as unwrap require the error to implement Debug. So we'd have to add a T: Debug bound.

@ndelvalle
Copy link

@hjiayz can you take a look at the PR 🙏🏼, and thanks for the lib btw!

drop(wakers);
return Poll::Ready(unsafe { &*ptr });

let mut fut = self.fut.lock();
Copy link
Author

Choose a reason for hiding this comment

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

Just noticed, that a second self.value.get() is required here, since the value might have been set by whoever held the mutex before, and polling a future after it's ready can lead to panics, depending on the implementation.

@@ -17,6 +17,10 @@ license = 'MIT OR Apache-2.0'
name = "benchmark"
harness = false

[dependencies]
parking_lot = "0.12.1"
Copy link
Author

Choose a reason for hiding this comment

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

At this point in time, parking_lot is no longer recommended over the std Mutex, since std now uses futex on Linux, which performs better in most cases.

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.

Code is unsound
2 participants