File: threaded.rs

package info (click to toggle)
rust-static-alloc 0.2.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 284 kB
  • sloc: makefile: 4
file content (21 lines) | stat: -rw-r--r-- 521 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use static_alloc::Bump;
use std::thread;

#[test]
fn each_thread_one() {
    const COUNT: usize = 10;
    // Static but not the global allocator.
    static BUMP: Bump<[u64; COUNT]> = Bump::uninit();

    let threads = (0..COUNT).map(|i| thread::spawn(move || {
        BUMP.leak(i).unwrap();
    })).collect::<Vec<_>>();

    threads
        .into_iter()
        .try_for_each(thread::JoinHandle::join)
        .expect("No thread failed to allocate");

    // But now no more left.
    assert!(BUMP.leak(0).is_err());
}