Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to thread::scope in tests #239

Merged
merged 2 commits into from Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
107 changes: 53 additions & 54 deletions Cargo.lock.msrv

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions Cargo.toml
Expand Up @@ -25,8 +25,6 @@ atomic-polyfill = { version = "1", optional = true }
critical-section = { version = "1", optional = true }

[dev-dependencies]
lazy_static = "1.0.0"
crossbeam-utils = "0.8.7"
regex = "1.2.0"
critical-section = { version = "1.1.1", features = ["std"] }

Expand Down Expand Up @@ -67,10 +65,6 @@ required-features = ["std"]
name = "bench_acquire"
required-features = ["std"]

[[example]]
name = "bench_vs_lazy_static"
required-features = ["std"]

[[example]]
name = "lazy_static"
required-features = ["std"]
Expand Down
51 changes: 0 additions & 51 deletions examples/bench_vs_lazy_static.rs

This file was deleted.

20 changes: 8 additions & 12 deletions tests/it/race.rs
Expand Up @@ -3,10 +3,9 @@ use std::sync::Barrier;
use std::{
num::NonZeroUsize,
sync::atomic::{AtomicUsize, Ordering::SeqCst},
thread::scope,
};

use crossbeam_utils::thread::scope;

use once_cell::race::{OnceBool, OnceNonZeroUsize};

#[test]
Expand All @@ -15,7 +14,7 @@ fn once_non_zero_usize_smoke_test() {
let cell = OnceNonZeroUsize::new();
let val = NonZeroUsize::new(92).unwrap();
scope(|s| {
s.spawn(|_| {
s.spawn(|| {
assert_eq!(
cell.get_or_init(|| {
cnt.fetch_add(1, SeqCst);
Expand All @@ -34,8 +33,7 @@ fn once_non_zero_usize_smoke_test() {
);
assert_eq!(cnt.load(SeqCst), 1);
});
})
.unwrap();
});
assert_eq!(cell.get(), Some(val));
assert_eq!(cnt.load(SeqCst), 1);
}
Expand Down Expand Up @@ -66,7 +64,7 @@ fn once_non_zero_usize_first_wins() {
let b2 = Barrier::new(2);
let b3 = Barrier::new(2);
scope(|s| {
s.spawn(|_| {
s.spawn(|| {
let r1 = cell.get_or_init(|| {
b1.wait();
b2.wait();
Expand All @@ -76,16 +74,15 @@ fn once_non_zero_usize_first_wins() {
b3.wait();
});
b1.wait();
s.spawn(|_| {
s.spawn(|| {
let r2 = cell.get_or_init(|| {
b2.wait();
b3.wait();
val2
});
assert_eq!(r2, val1);
});
})
.unwrap();
});

assert_eq!(cell.get(), Some(val1));
}
Expand All @@ -95,7 +92,7 @@ fn once_bool_smoke_test() {
let cnt = AtomicUsize::new(0);
let cell = OnceBool::new();
scope(|s| {
s.spawn(|_| {
s.spawn(|| {
assert_eq!(
cell.get_or_init(|| {
cnt.fetch_add(1, SeqCst);
Expand All @@ -114,8 +111,7 @@ fn once_bool_smoke_test() {
);
assert_eq!(cnt.load(SeqCst), 1);
});
})
.unwrap();
});
assert_eq!(cell.get(), Some(false));
assert_eq!(cnt.load(SeqCst), 1);
}
Expand Down