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

Unsound: Atom accepts an unsafe memory ordering #15

Open
yvt opened this issue Sep 19, 2021 · 2 comments · May be fixed by #17
Open

Unsound: Atom accepts an unsafe memory ordering #15

yvt opened this issue Sep 19, 2021 · 2 comments · May be fixed by #17

Comments

@yvt
Copy link

yvt commented Sep 19, 2021

This crate has the same issue as mystor/atomic_ref#5.

The following code segfaults on an AArch64 machine (but not on x86_64, which has a stronger memory model).

#![deny(unsafe_code)]
use atom::Atom;
use std::sync::atomic::Ordering;

fn main() {
    let channel = &*Box::leak(Box::new(Atom::<&&'static u32>::new(&&42u32)));

    std::thread::spawn(move || loop {
        if let Some(ptr) = channel.take(Ordering::Relaxed) {
            assert_eq!(**ptr, 42);
        }
    });

    for i in 0..10000000 {
        let b = Box::leak(Box::new(&42u32));
        channel.swap(b, Ordering::Relaxed);
    }
}
@yvt yvt changed the title Atom accepts an unsafe memory ordering Unsound: Atom accepts an unsafe memory ordering Sep 19, 2021
torkleyy added a commit that referenced this issue Oct 8, 2021
@torkleyy torkleyy linked a pull request Oct 8, 2021 that will close this issue
@torkleyy
Copy link
Member

torkleyy commented Oct 8, 2021

Thank you for the report, can you review #17 and tell me if it's fixed, please?

@elidupree
Copy link

I hope this can be fixed at some point. I want to use this crate, because Atom is exactly the synchronization primitive that I've wanted for several of my projects, and I appreciate the work that's gone into developing it. But I can't bring myself to use a dependency that has been "known to be unsound" for nearly a year without being updated...

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 a pull request may close this issue.

3 participants