Skip to content

Commit 8c980b7

Browse files
committed
Make crossbeam-epoch compatible with ThreadSanitizer
1 parent ce31c18 commit 8c980b7

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

ci/tsan

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# TSAN suppressions file for crossbeam
22

3-
# The epoch-based GC uses fences.
4-
race:crossbeam_epoch
5-
63
# Push and steal operations in crossbeam-deque may cause data races, but such
74
# data races are safe. If a data race happens, the value read by `steal` is
85
# forgotten and the steal operation is then retried.

crossbeam-epoch/build.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,10 @@ fn main() {
5454
if !cfg.probe_rustc_version(1, 61) {
5555
println!("cargo:rustc-cfg=crossbeam_no_const_fn_trait_bound");
5656
}
57+
58+
// `cfg(sanitize = "..")` is not stabilized.
59+
let sanitize = env::var("CARGO_CFG_SANITIZE").unwrap_or_default();
60+
if sanitize.contains("thread") {
61+
println!("cargo:rustc-cfg=crossbeam_sanitize_thread");
62+
}
5763
}

crossbeam-epoch/src/internal.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,16 @@ impl Global {
250250
if local_epoch.is_pinned() && local_epoch.unpinned() != global_epoch {
251251
return global_epoch;
252252
}
253+
254+
if cfg!(crossbeam_sanitize_thread) {
255+
local.epoch.load(Ordering::Acquire);
256+
}
253257
}
254258
}
255259
}
256-
atomic::fence(Ordering::Acquire);
260+
if !cfg!(crossbeam_sanitize_thread) {
261+
atomic::fence(Ordering::Acquire);
262+
}
257263

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

0 commit comments

Comments
 (0)