Skip to content

Commit

Permalink
Make crossbeam-epoch compatible with ThreadSanitizer
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Dec 2, 2023
1 parent a57e655 commit b9eb476
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
3 changes: 0 additions & 3 deletions ci/tsan
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# TSAN suppressions file for crossbeam

# The epoch-based GC uses fences.
race:crossbeam_epoch

# Push and steal operations in crossbeam-deque may cause data races, but such
# data races are safe. If a data race happens, the value read by `steal` is
# forgotten and the steal operation is then retried.
Expand Down
13 changes: 13 additions & 0 deletions crossbeam-epoch/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// The rustc-cfg emitted by the build script are *not* public API.

use std::env;

fn main() {
println!("cargo:rerun-if-changed=no_atomic.rs");

// `cfg(sanitize = "..")` is not stabilized.
let sanitize = env::var("CARGO_CFG_SANITIZE").unwrap_or_default();
if sanitize.contains("thread") {
println!("cargo:rustc-cfg=crossbeam_sanitize_thread");
}
}
8 changes: 7 additions & 1 deletion crossbeam-epoch/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,16 @@ impl Global {
if local_epoch.is_pinned() && local_epoch.unpinned() != global_epoch {
return global_epoch;
}

if cfg!(crossbeam_sanitize_thread) {
local.epoch.load(Ordering::Acquire);
}
}
}
}
atomic::fence(Ordering::Acquire);
if !cfg!(crossbeam_sanitize_thread) {
atomic::fence(Ordering::Acquire);
}

// All pinned participants were pinned in the current global epoch.
// Now let's advance the global epoch...
Expand Down

0 comments on commit b9eb476

Please sign in to comment.