mirror of
https://github.com/bdwgc/bdwgc-rust.git
synced 2026-05-29 18:08:56 -06:00
Fix test
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
use bdwgc_alloc::Allocator;
|
use bdwgc_alloc::Allocator;
|
||||||
use std::alloc::{alloc, Layout};
|
use std::{
|
||||||
|
alloc::{alloc, Layout},
|
||||||
|
thread::spawn,
|
||||||
|
};
|
||||||
|
|
||||||
const BITS: usize = 7 << 48;
|
const BITS: usize = 7 << 48;
|
||||||
|
|
||||||
@@ -9,17 +12,25 @@ static GLOBAL_ALLOCATOR: Allocator = Allocator;
|
|||||||
fn main() {
|
fn main() {
|
||||||
unsafe { Allocator::initialize() }
|
unsafe { Allocator::initialize() }
|
||||||
|
|
||||||
let mut xs = vec![];
|
let t1 = spawn(|| loop {
|
||||||
|
let ptr = allocate();
|
||||||
|
unsafe { *ptr = 0 };
|
||||||
|
});
|
||||||
|
|
||||||
for i in 0..10000000 {
|
let t2 = spawn(|| {
|
||||||
let ptr = unsafe { alloc(Layout::new::<usize>()) } as *mut usize;
|
let x = allocate();
|
||||||
|
|
||||||
unsafe { *ptr = i };
|
unsafe { *x = 42 };
|
||||||
|
|
||||||
xs.push(ptr as usize | BITS);
|
loop {
|
||||||
|
assert_eq!(unsafe { *((x as usize & !BITS) as *mut usize) }, 42);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
for x in xs {
|
t1.join().unwrap();
|
||||||
println!("{}", unsafe { *((x & !BITS) as *mut usize) });
|
t2.join().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn allocate() -> *mut usize {
|
||||||
|
(unsafe { alloc(Layout::new::<usize>()) }) as *mut usize
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user