1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#![feature(allocator_api)]
#![feature(try_reserve)]
#![feature(box_into_pin)]
#![feature(generators, generator_trait)]
#![feature(generic_associated_types)]
#![feature(type_alias_impl_trait)]
#![feature(concat_idents)]

extern crate alloc;

use core::ops::Range;

use ksched::task;
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};

pub mod fs;

pub fn rand_str(len: usize) -> String {
    thread_rng()
        .sample_iter(&Alphanumeric)
        .take(len)
        .map(char::from)
        .collect()
}

pub fn rand_int(range: Range<usize>) -> usize {
    let mut rng = rand::thread_rng();
    rng.gen_range(range)
}

pub fn run_multi(ncpu: usize) {
    let mut threads = vec![];
    for _ in 0..ncpu {
        let t = std::thread::spawn(move || {
            task::run();
        });
        threads.push(t);
    }
    for thread in threads {
        thread.join().unwrap();
    }
}