1 // Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
13 use comm::{GenericChan, GenericPort};
35 Start a new thread outside of the current runtime context and wait
38 The executing thread has no access to a task pointer and will be using
41 pub fn run_in_bare_thread(f: ~fn()) {
42 let (port, chan) = comm::stream();
43 // FIXME #4525: Unfortunate that this creates an extra scheduler but it's
44 // necessary since rust_raw_thread_join_delete is blocking
45 do task::spawn_sched(task::SingleThreaded) {
47 let closure: &fn() = || {
50 let thread = rust_raw_thread_start(&closure);
51 rust_raw_thread_join_delete(thread);
59 fn test_run_in_bare_thread() {
61 do run_in_bare_thread {
67 fn test_run_in_bare_thread_exchange() {
68 // Does the exchange heap work without the runtime?
70 do run_in_bare_thread {
75 #[allow(non_camel_case_types)] // runtime type
76 pub type raw_thread = libc::c_void;
79 fn rust_raw_thread_start(f: &(&fn())) -> *raw_thread;
80 fn rust_raw_thread_join_delete(thread: *raw_thread);