]> git.lizzy.rs Git - rust.git/blob - src/libstd/unstable/mod.rs
c7e88b7e161225e68e970965e386630f723d36b2
[rust.git] / src / libstd / unstable / mod.rs
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.
4 //
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.
10
11 #[doc(hidden)];
12
13 use comm::{GenericChan, GenericPort};
14 use comm;
15 use libc;
16 use prelude::*;
17 use task;
18
19 pub mod at_exit;
20
21 pub mod dynamic_lib;
22
23 pub mod global;
24 pub mod finally;
25 pub mod intrinsics;
26 pub mod simd;
27 pub mod extfmt;
28 #[cfg(not(test))]
29 pub mod lang;
30 pub mod sync;
31 pub mod atomics;
32
33 /**
34
35 Start a new thread outside of the current runtime context and wait
36 for it to terminate.
37
38 The executing thread has no access to a task pointer and will be using
39 a normal large stack.
40 */
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) {
46         unsafe {
47             let closure: &fn() = || {
48                 f()
49             };
50             let thread = rust_raw_thread_start(&closure);
51             rust_raw_thread_join_delete(thread);
52             chan.send(());
53         }
54     }
55     port.recv();
56 }
57
58 #[test]
59 fn test_run_in_bare_thread() {
60     let i = 100;
61     do run_in_bare_thread {
62         assert_eq!(i, 100);
63     }
64 }
65
66 #[test]
67 fn test_run_in_bare_thread_exchange() {
68     // Does the exchange heap work without the runtime?
69     let i = ~100;
70     do run_in_bare_thread {
71         assert!(i == ~100);
72     }
73 }
74
75 #[allow(non_camel_case_types)] // runtime type
76 pub type raw_thread = libc::c_void;
77
78 extern {
79     fn rust_raw_thread_start(f: &(&fn())) -> *raw_thread;
80     fn rust_raw_thread_join_delete(thread: *raw_thread);
81 }