1
0
Fork 0
libfringe/examples/basic.rs

25 lines
590 B
Rust
Raw Normal View History

2015-04-16 20:06:57 +08:00
// This file is part of libfringe, a low-level green threading library.
// Copyright (c) 2015, edef <edef@edef.eu>
// See the LICENSE file included in this distribution.
#![feature(thread_local)]
2015-04-16 20:06:57 +08:00
extern crate fringe;
use fringe::Context;
2014-12-23 11:24:40 +08:00
#[thread_local]
2015-04-16 20:06:57 +08:00
static mut ctx_slot: *mut Context<'static, fringe::OsStack> = 0 as *mut Context<_>;
2014-12-23 11:24:40 +08:00
fn main() {
unsafe {
2015-04-16 20:06:57 +08:00
let stack = fringe::OsStack::new(4 << 20).unwrap();
let mut ctx = Context::new(stack, move || {
println!("it's alive!");
(*ctx_slot).swap();
});
2014-12-23 11:24:40 +08:00
ctx_slot = &mut ctx;
2014-12-23 11:24:40 +08:00
(*ctx_slot).swap();
2014-12-23 11:24:40 +08:00
}
}