Add coroutine support

This commit is contained in:
Yota Toyama
2019-04-29 15:46:01 +00:00
parent 56d2f54060
commit a63a24d4d2
8 changed files with 234 additions and 2 deletions

View File

@@ -0,0 +1,28 @@
extern crate bdwgc_alloc;
extern crate coroutine;
use bdwgc_alloc::Allocator;
use coroutine::asymmetric::Coroutine;
use std::alloc::{GlobalAlloc, Layout};
#[global_allocator]
static GLOBAL_ALLOCATOR: Allocator = Allocator;
fn main() {
unsafe {
Allocator::initialize();
Allocator::disable_gc();
}
let handle = Coroutine::spawn(move |_, _| {
let bottom: u8 = 0;
unsafe { Allocator::set_stack_bottom(&bottom) }
Allocator::enable_gc();
loop {
unsafe { GLOBAL_ALLOCATOR.alloc(Layout::from_size_align(2 ^ 8, 8).unwrap()) };
}
});
for _ in handle {}
}