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

Once breaks if moved #119

Open
bkragl opened this issue Jul 4, 2023 · 1 comment
Open

Once breaks if moved #119

bkragl opened this issue Jul 4, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@bkragl
Copy link
Contributor

bkragl commented Jul 4, 2023

Here's a test that illustrates the bug:

#[test]
fn once_test() {
    crate::check_dfs(
        || {
            let once = Once::new();
            once.call_once(|| {});
            assert_eq!(is_completed_borrowed(&once), true);
            assert_eq!(is_completed_owned(once), true); // FAILS
        },
        None,
    );
}

fn is_completed_borrowed(once: &Once) -> bool {
    once.is_completed()
}

fn is_completed_owned(once: Once) -> bool {
    once.is_completed()
}

The issue is that we use the address of the Once to compute a storage key, which changes when the Once is moved.

shuttle/src/sync/once.rs

Lines 166 to 170 in 2ac1fae

impl From<&Once> for StorageKey {
fn from(once: &Once) -> Self {
StorageKey(once as *const _ as usize, 0x2)
}
}

@bkragl bkragl added the bug Something isn't working label Jul 4, 2023
@jamesbornholt
Copy link
Member

Hmm, yeah, that's pretty silly. Once should just use a static counter or something to generate unique storage keys. Or I guess a Box<usize> if we wanted to keep using addresses for some reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants