Skip to content

Commit 1c56672

Browse files
authored
Merge pull request #283 from japaric/rm-scoped_threadpool
use std::thread::scope instead of scoped_threadpool
2 parents 9fb9cd7 + 57ac20e commit 1c56672

File tree

4 files changed

+44
-27
lines changed

4 files changed

+44
-27
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ mpmc_large = []
2727
# This flag has no version guarantee, the `defmt` dependency can be updated in a patch release
2828
defmt-impl = ["defmt"]
2929

30-
[target.'cfg(not(target_os = "none"))'.dev-dependencies]
31-
scoped_threadpool = "0.1.8"
32-
3330
[target.thumbv6m-none-eabi.dependencies]
3431
atomic-polyfill = { version = "0.1.2", optional = true }
3532

@@ -65,5 +62,8 @@ version = "0.1"
6562
version = ">=0.2.0,<0.4"
6663
optional = true
6764

65+
[build-dependencies]
66+
rustc_version = "0.4.0"
67+
6868
[package.metadata.docs.rs]
6969
all-features = true

build.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
use std::{env, error::Error};
44

5+
use rustc_version::Channel;
6+
57
fn main() -> Result<(), Box<dyn Error>> {
68
let target = env::var("TARGET")?;
79

@@ -66,5 +68,12 @@ fn main() -> Result<(), Box<dyn Error>> {
6668
_ => {}
6769
}
6870

71+
if !matches!(
72+
rustc_version::version_meta().unwrap().channel,
73+
Channel::Stable | Channel::Beta
74+
) {
75+
println!("cargo:rustc-cfg=unstable_channel");
76+
}
77+
6978
Ok(())
7079
}

suppressions.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# false positives in thread::spawn (?)
2-
race:*dealloc
3-
race:*drop_slow*
4-
race:__call_tls_dtors
1+
race:std::panic::catch_unwind
2+
race:std::thread::scope
53

6-
# false positives in scoped_threadpool (?)
7-
race:*drop*
4+
# std::thread::spawn false positive; seen on Ubuntu 20.04 but not on Arch Linux (2022-04-29)
5+
race:drop_in_place*JoinHandle
6+
race:alloc::sync::Arc<*>::drop_slow
7+
race:__call_tls_dtors

tests/tsan.rs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
#![cfg_attr(unstable_channel, feature(scoped_threads))]
12
#![deny(rust_2018_compatibility)]
23
#![deny(rust_2018_idioms)]
34
#![deny(warnings)]
45

5-
use std::{sync::mpsc, thread};
6+
use std::thread;
67

7-
use heapless::{mpmc::Q64, spsc};
8-
use scoped_threadpool::Pool;
8+
use heapless::spsc;
99

1010
#[test]
1111
fn once() {
@@ -51,6 +51,7 @@ fn twice() {
5151
}
5252

5353
#[test]
54+
#[cfg(unstable_channel)]
5455
fn scoped() {
5556
let mut rb: spsc::Queue<i32, 5> = spsc::Queue::new();
5657

@@ -59,12 +60,12 @@ fn scoped() {
5960
{
6061
let (mut p, mut c) = rb.split();
6162

62-
Pool::new(2).scoped(move |scope| {
63-
scope.execute(move || {
63+
thread::scope(move |scope| {
64+
scope.spawn(move || {
6465
p.enqueue(1).unwrap();
6566
});
6667

67-
scope.execute(move || {
68+
scope.spawn(move || {
6869
c.dequeue().unwrap();
6970
});
7071
});
@@ -75,6 +76,7 @@ fn scoped() {
7576

7677
#[test]
7778
#[cfg_attr(miri, ignore)] // too slow
79+
#[cfg(unstable_channel)]
7880
fn contention() {
7981
const N: usize = 1024;
8082

@@ -83,8 +85,8 @@ fn contention() {
8385
{
8486
let (mut p, mut c) = rb.split();
8587

86-
Pool::new(2).scoped(move |scope| {
87-
scope.execute(move || {
88+
thread::scope(move |scope| {
89+
scope.spawn(move || {
8890
let mut sum: u32 = 0;
8991

9092
for i in 0..(2 * N) {
@@ -95,7 +97,7 @@ fn contention() {
9597
println!("producer: {}", sum);
9698
});
9799

98-
scope.execute(move || {
100+
scope.spawn(move || {
99101
let mut sum: u32 = 0;
100102

101103
for _ in 0..(2 * N) {
@@ -120,15 +122,20 @@ fn contention() {
120122

121123
#[test]
122124
#[cfg_attr(miri, ignore)] // too slow
125+
#[cfg(unstable_channel)]
123126
fn mpmc_contention() {
127+
use std::sync::mpsc;
128+
129+
use heapless::mpmc::Q64;
130+
124131
const N: u32 = 64;
125132

126133
static Q: Q64<u32> = Q64::new();
127134

128135
let (s, r) = mpsc::channel();
129-
Pool::new(2).scoped(|scope| {
136+
thread::scope(|scope| {
130137
let s1 = s.clone();
131-
scope.execute(move || {
138+
scope.spawn(move || {
132139
let mut sum: u32 = 0;
133140

134141
for i in 0..(16 * N) {
@@ -141,7 +148,7 @@ fn mpmc_contention() {
141148
});
142149

143150
let s2 = s.clone();
144-
scope.execute(move || {
151+
scope.spawn(move || {
145152
let mut sum: u32 = 0;
146153

147154
for _ in 0..(16 * N) {
@@ -166,6 +173,7 @@ fn mpmc_contention() {
166173

167174
#[test]
168175
#[cfg_attr(miri, ignore)] // too slow
176+
#[cfg(unstable_channel)]
169177
fn unchecked() {
170178
const N: usize = 1024;
171179

@@ -178,14 +186,14 @@ fn unchecked() {
178186
{
179187
let (mut p, mut c) = rb.split();
180188

181-
Pool::new(2).scoped(move |scope| {
182-
scope.execute(move || {
189+
thread::scope(move |scope| {
190+
scope.spawn(move || {
183191
for _ in 0..N / 2 - 1 {
184192
p.enqueue(2).unwrap();
185193
}
186194
});
187195

188-
scope.execute(move || {
196+
scope.spawn(move || {
189197
let mut sum: usize = 0;
190198

191199
for _ in 0..N / 2 - 1 {
@@ -246,8 +254,8 @@ fn pool() {
246254

247255
A::grow(unsafe { &mut M });
248256

249-
Pool::new(2).scoped(move |scope| {
250-
scope.execute(move || {
257+
thread::scope(move |scope| {
258+
scope.spawn(move || {
251259
for _ in 0..N / 4 {
252260
let a = A::alloc().unwrap();
253261
let b = A::alloc().unwrap();
@@ -257,7 +265,7 @@ fn pool() {
257265
}
258266
});
259267

260-
scope.execute(move || {
268+
scope.spawn(move || {
261269
for _ in 0..N / 2 {
262270
let a = A::alloc().unwrap();
263271
let a = a.init([2; 8]);

0 commit comments

Comments
 (0)