Skip to content

Commit

Permalink
Switch to standard scoped threads
Browse files Browse the repository at this point in the history
  • Loading branch information
HadrienG2 committed Aug 15, 2022
1 parent 5978847 commit dd5f34c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Expand Up @@ -94,7 +94,7 @@ jobs:
- macos-latest
rust:
- stable
- 1.38.0 # Minimum supported Rust version
- 1.63.0 # Minimum supported Rust version

steps:
- name: Checkout sources
Expand Down Expand Up @@ -148,7 +148,7 @@ jobs:
rust:
- beta
- nightly
- 1.38.0 # Minimum supported Rust version (can be changed by deps)
- 1.63.0 # Minimum supported Rust version (can be changed by deps)

steps:
- name: Checkout sources
Expand Down
15 changes: 13 additions & 2 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
_No unreleased changes in the pipeline at the moment._


## [1.0.0] - 2022-08-15

### Changed

- Switch from crossbeam scoped threads to std scoped threads. This bumps our
`rustc` requirements all the way up to the latest release (v1.63), but has the
great advantage that we are no longer bound by the ever shifting rustc
requirements of crossbeam, so this requirement can stay indefinitely.


## [0.9.0] - 2022-08-10

### Changed
Expand Down Expand Up @@ -181,8 +191,9 @@ _No unreleased changes in the pipeline at the moment._



[Unreleased]: https://github.com/HadrienG2/testbench/compare/v0.9.0...HEAD
[0.8.1]: https://github.com/HadrienG2/testbench/compare/v0.8.1...v0.9.0
[Unreleased]: https://github.com/HadrienG2/testbench/compare/v1.0.0...HEAD
[1.0.0]: https://github.com/HadrienG2/testbench/compare/v0.9.0...v1.0.0
[0.9.0]: https://github.com/HadrienG2/testbench/compare/v0.8.1...v0.9.0
[0.8.1]: https://github.com/HadrienG2/testbench/compare/v0.8.0...v0.8.1
[0.8.0]: https://github.com/HadrienG2/testbench/compare/v0.7.3...v0.8.0
[0.7.3]: https://github.com/HadrienG2/testbench/compare/v0.7.2...v0.7.3
Expand Down
7 changes: 2 additions & 5 deletions Cargo.toml
Expand Up @@ -12,7 +12,7 @@ name = "testbench"
# - Cargo publish.
# - Add a github release
#
version = "0.9.0"
version = "1.0.0"
authors = ["Hadrien G. <knights_of_ni@gmx.com>"]
description = "Testing and benchmarking tools for concurrent Rust code"
documentation = "https://docs.rs/testbench/"
Expand All @@ -22,10 +22,7 @@ keywords = [ "testing", "benchmarking", "multithreading", "concurrent" ]
categories = [ "concurrency", "development-tools" ]
license = "MPL-2.0"
edition = "2018"
rust-version = "1.38.0"
rust-version = "1.63.0"

[badges]
maintenance = { status = "passively-maintained" }

[dependencies]
crossbeam-utils = "0.8"
18 changes: 7 additions & 11 deletions src/lib.rs
Expand Up @@ -31,7 +31,6 @@
pub mod noinline;
pub mod race_cell;

use crossbeam_utils::thread;
use std::sync::{
atomic::{AtomicBool, Ordering},
Barrier,
Expand All @@ -55,15 +54,14 @@ use std::sync::{
///
pub fn concurrent_test_2(f1: impl FnOnce() + Send, f2: impl FnOnce() + Send) {
let barrier = Barrier::new(2);
thread::scope(|s| {
s.spawn(|_| {
std::thread::scope(|s| {
s.spawn(|| {
barrier.wait();
noinline::call_once(f1);
});
barrier.wait();
noinline::call_once(f2);
})
.expect("Failed to join thread running f1");
}

/// Test that running three operations concurrently works
Expand All @@ -82,19 +80,18 @@ pub fn concurrent_test_3(
f3: impl FnOnce() + Send,
) {
let barrier = Barrier::new(3);
thread::scope(|s| {
s.spawn(|_| {
std::thread::scope(|s| {
s.spawn(|| {
barrier.wait();
noinline::call_once(f1);
});
s.spawn(|_| {
s.spawn(|| {
barrier.wait();
noinline::call_once(f2);
});
barrier.wait();
noinline::call_once(f3);
})
.expect("Failed to join threads running f1 and f2");
}

/// Perform some operation while another is running in a loop in another thread
Expand Down Expand Up @@ -126,8 +123,8 @@ pub fn run_under_contention<AntagonistResult, BenchmarkResult>(
) -> BenchmarkResult {
let start_barrier = Barrier::new(2);
let continue_flag = AtomicBool::new(true);
thread::scope(|s| {
s.spawn(|_| {
std::thread::scope(|s| {
s.spawn(|| {
start_barrier.wait();
while continue_flag.load(Ordering::Relaxed) {
antagonist();
Expand All @@ -138,7 +135,6 @@ pub fn run_under_contention<AntagonistResult, BenchmarkResult>(
continue_flag.store(false, Ordering::Relaxed);
result
})
.expect("Failed to join antagonist thread")
}

/// Examples of concurrent testing code
Expand Down

0 comments on commit dd5f34c

Please sign in to comment.