]> git.lizzy.rs Git - rust.git/blob - src/libstd/rt/thread.rs
Change finalize -> drop.
[rust.git] / src / libstd / rt / thread.rs
1 // Copyright 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 use libc;
12 use ops::Drop;
13
14 #[allow(non_camel_case_types)] // runtime type
15 type raw_thread = libc::c_void;
16
17 pub struct Thread {
18     main: ~fn(),
19     raw_thread: *raw_thread
20 }
21
22 impl Thread {
23     pub fn start(main: ~fn()) -> Thread {
24         fn substart(main: &~fn()) -> *raw_thread {
25             unsafe { rust_raw_thread_start(main) }
26         }
27         let raw = substart(&main);
28         Thread {
29             main: main,
30             raw_thread: raw
31         }
32     }
33 }
34
35 impl Drop for Thread {
36     fn drop(&self) {
37         unsafe { rust_raw_thread_join_delete(self.raw_thread) }
38     }
39 }
40
41 extern {
42     pub unsafe fn rust_raw_thread_start(f: &(~fn())) -> *raw_thread;
43     pub unsafe fn rust_raw_thread_join_delete(thread: *raw_thread);
44 }