Skip to content

Unexpected non-determinism with thread::scope (but only on some targets) #4737

@RalfJung

Description

@RalfJung

The following test should always pass with -Zmiri-fixed-schedule:

use std::thread;

fn main() {
    thread::scope(|s| {
        s.spawn(|| {
            thread::yield_now();
            std::process::abort();
        });
        s.spawn(|| {
            std::process::exit(0);
        });
    });
}

We will always run the first thread, yield, go to the second thread, and exit, therefore never reaching the abort (which would fail the test). On x86_64-unknown-linux-gnu, i686-unknown-linux-gnu, and armv7-unknown-linux-gnueabihf, this indeed behaves as expected.

However, on mips-unknown-linux-gnu, the test sometimes (for around 33% of the seeds) does hit the abort and fail. I have no idea how that is possible. This behavior also only very recently started with a rustup covering this upstream diff: rust-lang/rust@1eb0657...3ff30e7. That includes rust-lang/rust#148765 which is described as merely moving code around but maybe something changed somewhere...? It also includes rust-lang/rust#144465 which is more likely to be the culprit as that mips target does not have 64bit atomics. Cc @joboet @orlp

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions