Files
bdwgc-rust/examples/dynamic_threads/src/main.rs
2023-09-28 10:51:38 +08:00

24 lines
563 B
Rust

use bdwgc_alloc::Allocator;
use std::alloc::Layout;
#[global_allocator]
static GLOBAL_ALLOCATOR: Allocator = Allocator;
fn main() {
unsafe { Allocator::initialize() }
loop {
let handle = std::thread::spawn(move || {
unsafe { Allocator::register_current_thread().unwrap() }
for _ in 0..100 {
let _ = unsafe { std::alloc::alloc(Layout::from_size_align(2 ^ 8, 8).unwrap()) };
}
unsafe { Allocator::unregister_current_thread() }
});
handle.join().unwrap();
}
}