crossbeam-rs / crossbeam

Tools for concurrent programming in Rust
Apache License 2.0
7.33k stars 461 forks source link

A question regarding Miri error running the “sanitize" example under crossbeam-epoch. #1108

Open lshi18 opened 4 months ago

lshi18 commented 4 months ago

Hello, when I ran the sanitize example under crossbeam-epoch using Miri, I got an undefined behaviour error. As I am new to crossbeam, could you please offer some insight as to what could be the cause of the error? Thank you.

The command I used,

$ MIRIFLAGS="-Zmiri-symbolic-alignment-check -Zmiri-disable-isolation -Zmiri-tree-borrows" cargo miri run -p crossbeam-epoch --example sanitize

and the error,

error: Undefined Behavior: Data race detected between (1) atomic load on thread `unnamed-4` and (2) retag read of type `std::sync::atomic::AtomicUsize` on thread `unnamed-5` at alloc1563563. (2) just happened here
    --> /Users/lei.shi/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/boxed.rs:1008:9
     |
1008 |         Box(unsafe { Unique::new_unchecked(raw) }, alloc)
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between (1) atomic load on thread `unnamed-4` and (2) retag read of type `std::sync::atomic::AtomicUsize` on thread `unnamed-5` at alloc1563563. (2) just happened here
     |
help: and (1) occurred earlier here
    --> crossbeam-epoch/examples/sanitize.rs:30:21
     |
30   |                     p.deref().load(Relaxed)
     |                     ^^^^^^^^^^^^^^^^^^^^^^^
     = help: overlapping atomic and non-atomic accesses must be synchronized, even if both are read-only
     = help: see https://doc.rust-lang.org/nightly/std/sync/atomic/index.html#memory-model-for-atomic-accesses for more information about the Rust memory model
     = help: retags occur on all (re)borrows and as well as when references are copied or moved
     = help: retags permit optimizations that insert speculative reads or writes
     = help: therefore from the perspective of data races, a retag has the same implications as a read or write
     = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
     = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

Environment,