Skip to content

Commit

Permalink
epoch: Make loom able to test treiber stack
Browse files Browse the repository at this point in the history
With this change, loom runs to completion on the treiber test!
I ran it with `LOOM_MAX_PREEMPTIONS=3`, and it took _forever_ (well, it
took 2h), but eventually finished with:

     ================== Iteration 112280000 ==================

    Completed in 112291514 iterations
    ok

With `LOOM_MAX_PREEMPTIONS=2` it "only" took 13 minutes, and finished
with:

     ================== Iteration 9680000 ==================

    Completed in 9690926 iterations
    ok

I updated the CI script to run with `LOOM_MAX_PREEMPTIONS=2`.

Note that this change depends on
tokio-rs/loom#125 and
tokio-rs/loom#128. The `patch` in the root
`Cargo.toml` should be removed once a new loom release is made.
  • Loading branch information
jonhoo committed Apr 12, 2020
1 parent d88844d commit 08b37ab
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,6 @@ members = [
"crossbeam-skiplist",
"crossbeam-utils",
]

[patch.crates-io]
loom = { git = "https://github.com/jonhoo/loom.git", branch = "lazy_static-race" }
2 changes: 1 addition & 1 deletion ci/crossbeam-epoch-loom.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set -ex

export RUSTFLAGS="-D warnings"

env LOOM_MAX_PREEMPTIONS=3 cargo test --test loom --features with-loom --release -- --nocapture
env LOOM_MAX_PREEMPTIONS=2 cargo test --test loom --features with-loom --release -- --nocapture
2 changes: 1 addition & 1 deletion crossbeam-epoch/src/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use collector::{Collector, LocalHandle};
use guard::Guard;

lazy_static! {
::concurrency::lazy_static! {
/// The global data for the default garbage collector.
static ref COLLECTOR: Collector = Collector::new();
}
Expand Down
14 changes: 13 additions & 1 deletion crossbeam-epoch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ pub(crate) mod concurrency {
pub(crate) use loom::sync::Arc;
}
pub(crate) use loom::thread_local;

cfg_if! {
if #[cfg(feature = "std")] {
pub(crate) use loom::lazy_static;
}
}
}
#[cfg(not(feature = "with-loom"))]
pub(crate) mod concurrency {
Expand Down Expand Up @@ -126,6 +132,13 @@ pub(crate) mod concurrency {
pub(crate) use alloc::sync::Arc;
}
pub(crate) use std::thread_local;
pub(crate) use std::thread_local;

cfg_if! {
if #[cfg(feature = "std")] {
pub(crate) use lazy_static::lazy_static;
}
}
}

cfg_if! {
Expand Down Expand Up @@ -161,7 +174,6 @@ cfg_if! {

cfg_if! {
if #[cfg(feature = "std")] {
#[macro_use]
extern crate lazy_static;

mod default;
Expand Down
5 changes: 3 additions & 2 deletions crossbeam-epoch/tests/loom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,15 @@ fn treiber_stack() {
let stack1 = Arc::new(TreiberStack::new());
let stack2 = Arc::clone(&stack1);

// use 5 since it's greater than the 4 used for the sanitize feature
let jh = spawn(move || {
for i in 0..20 {
for i in 0..5 {
stack2.push(i);
assert!(stack2.pop().is_some());
}
});

for i in 0..20 {
for i in 0..5 {
stack1.push(i);
assert!(stack1.pop().is_some());
}
Expand Down

0 comments on commit 08b37ab

Please sign in to comment.