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 Jun 17, 2023
1 parent ce31c18 commit 8c980b7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 0 additions & 3 deletions ci/tsan
@@ -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
6 changes: 6 additions & 0 deletions crossbeam-epoch/build.rs
Expand Up @@ -54,4 +54,10 @@ fn main() {
if !cfg.probe_rustc_version(1, 61) {
println!("cargo:rustc-cfg=crossbeam_no_const_fn_trait_bound");
}

// `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
Expand Up @@ -250,10 +250,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 8c980b7

Please sign in to comment.