mirror of
https://github.com/rust-embedded/heapless.git
synced 2025-10-02 14:54:30 +00:00
use std:🧵: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: https://github.com/japaric/heapless/pull/282#issuecomment-1113173358 std:🧵: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:🧵:scope tradeoffs: - pro: one less dev dependency - pro: supressions file is simpler - cons: std:🧵:scope is only available on recent nightlies
This commit is contained in:
parent
9fb9cd7045
commit
477c53b25d
@ -27,9 +27,6 @@ mpmc_large = []
|
|||||||
# This flag has no version guarantee, the `defmt` dependency can be updated in a patch release
|
# This flag has no version guarantee, the `defmt` dependency can be updated in a patch release
|
||||||
defmt-impl = ["defmt"]
|
defmt-impl = ["defmt"]
|
||||||
|
|
||||||
[target.'cfg(not(target_os = "none"))'.dev-dependencies]
|
|
||||||
scoped_threadpool = "0.1.8"
|
|
||||||
|
|
||||||
[target.thumbv6m-none-eabi.dependencies]
|
[target.thumbv6m-none-eabi.dependencies]
|
||||||
atomic-polyfill = { version = "0.1.2", optional = true }
|
atomic-polyfill = { version = "0.1.2", optional = true }
|
||||||
|
|
||||||
|
@ -1,7 +1,2 @@
|
|||||||
# false positives in thread::spawn (?)
|
race:std::panic::catch_unwind
|
||||||
race:*dealloc
|
race:std::thread::scope
|
||||||
race:*drop_slow*
|
|
||||||
race:__call_tls_dtors
|
|
||||||
|
|
||||||
# false positives in scoped_threadpool (?)
|
|
||||||
race:*drop*
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#![feature(scoped_threads)]
|
||||||
#![deny(rust_2018_compatibility)]
|
#![deny(rust_2018_compatibility)]
|
||||||
#![deny(rust_2018_idioms)]
|
#![deny(rust_2018_idioms)]
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
@ -5,7 +6,6 @@
|
|||||||
use std::{sync::mpsc, thread};
|
use std::{sync::mpsc, thread};
|
||||||
|
|
||||||
use heapless::{mpmc::Q64, spsc};
|
use heapless::{mpmc::Q64, spsc};
|
||||||
use scoped_threadpool::Pool;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn once() {
|
fn once() {
|
||||||
@ -59,12 +59,12 @@ fn scoped() {
|
|||||||
{
|
{
|
||||||
let (mut p, mut c) = rb.split();
|
let (mut p, mut c) = rb.split();
|
||||||
|
|
||||||
Pool::new(2).scoped(move |scope| {
|
thread::scope(move |scope| {
|
||||||
scope.execute(move || {
|
scope.spawn(move || {
|
||||||
p.enqueue(1).unwrap();
|
p.enqueue(1).unwrap();
|
||||||
});
|
});
|
||||||
|
|
||||||
scope.execute(move || {
|
scope.spawn(move || {
|
||||||
c.dequeue().unwrap();
|
c.dequeue().unwrap();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -83,8 +83,8 @@ fn contention() {
|
|||||||
{
|
{
|
||||||
let (mut p, mut c) = rb.split();
|
let (mut p, mut c) = rb.split();
|
||||||
|
|
||||||
Pool::new(2).scoped(move |scope| {
|
thread::scope(move |scope| {
|
||||||
scope.execute(move || {
|
scope.spawn(move || {
|
||||||
let mut sum: u32 = 0;
|
let mut sum: u32 = 0;
|
||||||
|
|
||||||
for i in 0..(2 * N) {
|
for i in 0..(2 * N) {
|
||||||
@ -95,7 +95,7 @@ fn contention() {
|
|||||||
println!("producer: {}", sum);
|
println!("producer: {}", sum);
|
||||||
});
|
});
|
||||||
|
|
||||||
scope.execute(move || {
|
scope.spawn(move || {
|
||||||
let mut sum: u32 = 0;
|
let mut sum: u32 = 0;
|
||||||
|
|
||||||
for _ in 0..(2 * N) {
|
for _ in 0..(2 * N) {
|
||||||
@ -126,9 +126,9 @@ fn mpmc_contention() {
|
|||||||
static Q: Q64<u32> = Q64::new();
|
static Q: Q64<u32> = Q64::new();
|
||||||
|
|
||||||
let (s, r) = mpsc::channel();
|
let (s, r) = mpsc::channel();
|
||||||
Pool::new(2).scoped(|scope| {
|
thread::scope(|scope| {
|
||||||
let s1 = s.clone();
|
let s1 = s.clone();
|
||||||
scope.execute(move || {
|
scope.spawn(move || {
|
||||||
let mut sum: u32 = 0;
|
let mut sum: u32 = 0;
|
||||||
|
|
||||||
for i in 0..(16 * N) {
|
for i in 0..(16 * N) {
|
||||||
@ -141,7 +141,7 @@ fn mpmc_contention() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let s2 = s.clone();
|
let s2 = s.clone();
|
||||||
scope.execute(move || {
|
scope.spawn(move || {
|
||||||
let mut sum: u32 = 0;
|
let mut sum: u32 = 0;
|
||||||
|
|
||||||
for _ in 0..(16 * N) {
|
for _ in 0..(16 * N) {
|
||||||
@ -178,14 +178,14 @@ fn unchecked() {
|
|||||||
{
|
{
|
||||||
let (mut p, mut c) = rb.split();
|
let (mut p, mut c) = rb.split();
|
||||||
|
|
||||||
Pool::new(2).scoped(move |scope| {
|
thread::scope(move |scope| {
|
||||||
scope.execute(move || {
|
scope.spawn(move || {
|
||||||
for _ in 0..N / 2 - 1 {
|
for _ in 0..N / 2 - 1 {
|
||||||
p.enqueue(2).unwrap();
|
p.enqueue(2).unwrap();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
scope.execute(move || {
|
scope.spawn(move || {
|
||||||
let mut sum: usize = 0;
|
let mut sum: usize = 0;
|
||||||
|
|
||||||
for _ in 0..N / 2 - 1 {
|
for _ in 0..N / 2 - 1 {
|
||||||
@ -246,8 +246,8 @@ fn pool() {
|
|||||||
|
|
||||||
A::grow(unsafe { &mut M });
|
A::grow(unsafe { &mut M });
|
||||||
|
|
||||||
Pool::new(2).scoped(move |scope| {
|
thread::pool(move |scope| {
|
||||||
scope.execute(move || {
|
scope.spawn(move || {
|
||||||
for _ in 0..N / 4 {
|
for _ in 0..N / 4 {
|
||||||
let a = A::alloc().unwrap();
|
let a = A::alloc().unwrap();
|
||||||
let b = A::alloc().unwrap();
|
let b = A::alloc().unwrap();
|
||||||
@ -257,7 +257,7 @@ fn pool() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
scope.execute(move || {
|
scope.spawn(move || {
|
||||||
for _ in 0..N / 2 {
|
for _ in 0..N / 2 {
|
||||||
let a = A::alloc().unwrap();
|
let a = A::alloc().unwrap();
|
||||||
let a = a.init([2; 8]);
|
let a = a.init([2; 8]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user