Skip to content

Commit 477c53b

Browse files
committed
use std::thread::scope instead of scoped_threadpool
as it's easier to deal with TSAN false positives in the former API as surfaced in PR 280 the current supression rules don't handle newer versions of the scoped_threadpool crate trying to update the supression rules related to scoped_threadpool in PR #282 revealed that the supression rules are masking (hiding) real data races: #282 (comment) std::thread::scope requires less supression rules and does not mask real data races -- for instance, the data race in the linked issue comment is not masked when using std::thread::scope tradeoffs: - pro: one less dev dependency - pro: supressions file is simpler - cons: std::thread::scope is only available on recent nightlies
1 parent 9fb9cd7 commit 477c53b

File tree

3 files changed

+18
-26
lines changed

3 files changed

+18
-26
lines changed

Cargo.toml

Lines changed: 0 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

suppressions.txt

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

tests/tsan.rs

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

56
use std::{sync::mpsc, thread};
67

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

1010
#[test]
1111
fn once() {
@@ -59,12 +59,12 @@ fn scoped() {
5959
{
6060
let (mut p, mut c) = rb.split();
6161

62-
Pool::new(2).scoped(move |scope| {
63-
scope.execute(move || {
62+
thread::scope(move |scope| {
63+
scope.spawn(move || {
6464
p.enqueue(1).unwrap();
6565
});
6666

67-
scope.execute(move || {
67+
scope.spawn(move || {
6868
c.dequeue().unwrap();
6969
});
7070
});
@@ -83,8 +83,8 @@ fn contention() {
8383
{
8484
let (mut p, mut c) = rb.split();
8585

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

9090
for i in 0..(2 * N) {
@@ -95,7 +95,7 @@ fn contention() {
9595
println!("producer: {}", sum);
9696
});
9797

98-
scope.execute(move || {
98+
scope.spawn(move || {
9999
let mut sum: u32 = 0;
100100

101101
for _ in 0..(2 * N) {
@@ -126,9 +126,9 @@ fn mpmc_contention() {
126126
static Q: Q64<u32> = Q64::new();
127127

128128
let (s, r) = mpsc::channel();
129-
Pool::new(2).scoped(|scope| {
129+
thread::scope(|scope| {
130130
let s1 = s.clone();
131-
scope.execute(move || {
131+
scope.spawn(move || {
132132
let mut sum: u32 = 0;
133133

134134
for i in 0..(16 * N) {
@@ -141,7 +141,7 @@ fn mpmc_contention() {
141141
});
142142

143143
let s2 = s.clone();
144-
scope.execute(move || {
144+
scope.spawn(move || {
145145
let mut sum: u32 = 0;
146146

147147
for _ in 0..(16 * N) {
@@ -178,14 +178,14 @@ fn unchecked() {
178178
{
179179
let (mut p, mut c) = rb.split();
180180

181-
Pool::new(2).scoped(move |scope| {
182-
scope.execute(move || {
181+
thread::scope(move |scope| {
182+
scope.spawn(move || {
183183
for _ in 0..N / 2 - 1 {
184184
p.enqueue(2).unwrap();
185185
}
186186
});
187187

188-
scope.execute(move || {
188+
scope.spawn(move || {
189189
let mut sum: usize = 0;
190190

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

247247
A::grow(unsafe { &mut M });
248248

249-
Pool::new(2).scoped(move |scope| {
250-
scope.execute(move || {
249+
thread::pool(move |scope| {
250+
scope.spawn(move || {
251251
for _ in 0..N / 4 {
252252
let a = A::alloc().unwrap();
253253
let b = A::alloc().unwrap();
@@ -257,7 +257,7 @@ fn pool() {
257257
}
258258
});
259259

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

0 commit comments

Comments
 (0)