2015-04-16 20:06:57 +08:00
|
|
|
// This file is part of libfringe, a low-level green threading library.
|
2016-03-22 15:25:23 +08:00
|
|
|
// Copyright (c) edef <edef@edef.eu>
|
2015-04-16 20:06:57 +08:00
|
|
|
// See the LICENSE file included in this distribution.
|
2015-01-14 15:31:17 +08:00
|
|
|
#![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
|
|
|
|
2015-01-14 15:31:17 +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
|
|
|
|
2015-01-14 15:31:17 +08:00
|
|
|
fn main() {
|
|
|
|
unsafe {
|
2015-04-16 20:06:57 +08:00
|
|
|
let stack = fringe::OsStack::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!");
|
2016-04-04 01:54:40 +08:00
|
|
|
Context::swap(ctx_slot, ctx_slot);
|
2015-08-25 12:42:26 +08:00
|
|
|
panic!("Do not come back!")
|
2015-01-14 15:31:17 +08:00
|
|
|
});
|
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
|
|
|
|
2016-04-04 01:54:40 +08:00
|
|
|
Context::swap(ctx_slot, ctx_slot);
|
2014-12-23 11:24:40 +08:00
|
|
|
}
|
|
|
|
}
|