rust/src/libstd/unstable/mod.rs

79 lines
1.9 KiB
Rust
Raw Normal View History

// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[doc(hidden)];
use libc;
2013-02-02 05:10:12 -06:00
use comm::{GenericChan, GenericPort};
use prelude::*;
use task;
2012-04-06 19:03:00 -05:00
2013-01-11 17:55:14 -06:00
pub mod at_exit;
pub mod global;
pub mod finally;
2013-01-15 21:53:35 -06:00
pub mod weak_task;
pub mod intrinsics;
pub mod simd;
pub mod extfmt;
#[cfg(not(test))]
pub mod lang;
pub mod sync;
2013-05-25 00:51:26 -05:00
pub mod atomics;
/**
2013-01-11 19:59:35 -06:00
Start a new thread outside of the current runtime context and wait
for it to terminate.
The executing thread has no access to a task pointer and will be using
a normal large stack.
*/
pub fn run_in_bare_thread(f: ~fn()) {
2013-02-02 05:10:12 -06:00
let (port, chan) = comm::stream();
2013-01-18 16:21:31 -06:00
// FIXME #4525: Unfortunate that this creates an extra scheduler but it's
// necessary since rust_raw_thread_join_delete is blocking
do task::spawn_sched(task::SingleThreaded) {
unsafe {
let closure: &fn() = || {
f()
};
let thread = rust_raw_thread_start(&closure);
rust_raw_thread_join_delete(thread);
chan.send(());
}
}
port.recv();
}
#[test]
fn test_run_in_bare_thread() {
let i = 100;
do run_in_bare_thread {
assert_eq!(i, 100);
}
}
#[test]
fn test_run_in_bare_thread_exchange() {
// Does the exchange heap work without the runtime?
let i = ~100;
do run_in_bare_thread {
2013-03-28 20:39:09 -05:00
assert!(i == ~100);
}
}
#[allow(non_camel_case_types)] // runtime type
pub type raw_thread = libc::c_void;
extern {
fn rust_raw_thread_start(f: &(&fn())) -> *raw_thread;
fn rust_raw_thread_join_delete(thread: *raw_thread);
}