about summary refs log tree commit diff
path: root/library/std/src/process/tests.rs
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2021-12-23 00:28:54 +0100
committerGitHub <noreply@github.com>2021-12-23 00:28:54 +0100
commit12e4907728eeeb658c1a8d528dbacab9ad485d25 (patch)
tree6412060e2cb80e8c1e6a5d6dfe4526d067c12ebd /library/std/src/process/tests.rs
parent554ad50fa24f88f5db83b8678b39410c51038ca7 (diff)
parent984b10da169bff9bcc1fcf75984467f0f218108a (diff)
downloadrust-12e4907728eeeb658c1a8d528dbacab9ad485d25.tar.gz
rust-12e4907728eeeb658c1a8d528dbacab9ad485d25.zip
Rollup merge of #92139 - dtolnay:backtrace, r=m-ou-se
Change Backtrace::enabled atomic from SeqCst to Relaxed

This atomic is not synchronizing anything outside of its own value, so we don't need the `Acquire`/`Release` guarantee that all memory operations prior to the store are visible after the subsequent load, nor the `SeqCst` guarantee of all threads seeing all of the sequentially consistent operations in the same order.

Using `Relaxed` reduces the overhead of `Backtrace::capture()` in the case that backtraces are not enabled.

## Benchmark

```rust
#![feature(backtrace)]

use std::backtrace::Backtrace;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::thread;
use std::time::Instant;

fn main() {
    let begin = Instant::now();
    let mut threads = Vec::new();
    for _ in 0..64 {
        threads.push(thread::spawn(|| {
            for _ in 0..10_000_000 {
                let _ = Backtrace::capture();
                static LOL: AtomicUsize = AtomicUsize::new(0);
                LOL.store(1, Ordering::Release);
            }
        }));
    }
    for thread in threads {
        let _ = thread.join();
    }
    println!("{:?}", begin.elapsed());
}
```

**Before:**&ensp;6.73 seconds
**After:**&ensp;5.18 seconds
Diffstat (limited to 'library/std/src/process/tests.rs')
0 files changed, 0 insertions, 0 deletions