2015-01-14 15:31:17 +08:00
|
|
|
#![feature(thread_local)]
|
2014-12-23 11:24:40 +08:00
|
|
|
extern crate lwkt;
|
2015-04-16 19:39:28 +08:00
|
|
|
use lwkt::Context;
|
2014-12-23 11:24:40 +08:00
|
|
|
|
2015-01-14 15:31:17 +08:00
|
|
|
#[thread_local]
|
2015-04-16 15:53:49 +08:00
|
|
|
static mut ctx_slot: *mut Context<'static, lwkt::os::Stack> = 0 as *mut Context<_>;
|
2014-12-23 11:24:40 +08:00
|
|
|
|
2015-01-14 15:31:17 +08:00
|
|
|
fn main() {
|
|
|
|
unsafe {
|
2015-04-16 19:39:28 +08:00
|
|
|
let stack = lwkt::os::Stack::new(4 << 20).unwrap();
|
2015-04-16 04:25:09 +08:00
|
|
|
|
|
|
|
let mut ctx = Context::new(stack, move || {
|
2015-01-14 15:31:17 +08:00
|
|
|
println!("it's alive!");
|
|
|
|
(*ctx_slot).swap();
|
|
|
|
});
|
2014-12-23 11:24:40 +08:00
|
|
|
|
2015-01-14 15:31:17 +08:00
|
|
|
ctx_slot = &mut ctx;
|
2014-12-23 11:24:40 +08:00
|
|
|
|
2015-01-14 15:31:17 +08:00
|
|
|
(*ctx_slot).swap();
|
2014-12-23 11:24:40 +08:00
|
|
|
}
|
|
|
|
}
|