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

Uniqueness requirement for UnsafeCell aliases violated in oneshot.rs #3

Closed
jganetsk opened this issue Dec 28, 2020 · 1 comment
Closed

Comments

@jganetsk
Copy link

jganetsk commented Dec 28, 2020

/// NOTE(unsafe): This function must not be used concurrently with itself,
/// but it can be used concurrently with put.
pub unsafe fn take(&self) -> Option<T> {

It is claimed that put and take can be called concurrently. Both methods call UnsafeCell::get()

Ensure that the access is unique (no active references, mutable or not) when casting to &mut T

But put calls MaybeUninit::write() which casts it to &mut MaybeUninit<T>. You do not guarantee that the reference is unique, given that there could be a concurrent &MaybeUninit<T> in a concurrent call to take.

@jganetsk
Copy link
Author

Nevermind, this is fine. The aliases should never exist at the same time.

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

No branches or pull requests

1 participant