about summary refs log tree commit diff
path: root/src/libstd/rt/thread.rs
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2013-07-27 12:05:15 -0700
committerBrian Anderson <banderson@mozilla.com>2013-07-30 14:23:44 -0700
commit0144c83213cb5ce43df61f149274379f49b6d7cb (patch)
treeaa4a8117325521e49c07bb1e5a679bad6f9827db /src/libstd/rt/thread.rs
parent7265cc6530b242f9590a3207f2bfdf9a5425a32c (diff)
std::rt: Change Thread interface to require an explicit join
Makes it more obvious what's going on
Diffstat (limited to 'src/libstd/rt/thread.rs')
-rw-r--r--src/libstd/rt/thread.rs19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/libstd/rt/thread.rs b/src/libstd/rt/thread.rs
index 98d08c060e0..ed0137d3b0f 100644
--- a/src/libstd/rt/thread.rs
+++ b/src/libstd/rt/thread.rs
@@ -16,7 +16,8 @@ type raw_thread = libc::c_void;
 
 pub struct Thread {
     main: ~fn(),
-    raw_thread: *raw_thread
+    raw_thread: *raw_thread,
+    joined: bool
 }
 
 impl Thread {
@@ -27,18 +28,28 @@ impl Thread {
         let raw = substart(&main);
         Thread {
             main: main,
-            raw_thread: raw
+            raw_thread: raw,
+            joined: false
         }
     }
+
+    pub fn join(self) {
+        assert!(!self.joined);
+        let mut this = self;
+        unsafe { rust_raw_thread_join(this.raw_thread); }
+        this.joined = true;
+    }
 }
 
 impl Drop for Thread {
     fn drop(&self) {
-        unsafe { rust_raw_thread_join_delete(self.raw_thread) }
+        assert!(self.joined);
+        unsafe { rust_raw_thread_delete(self.raw_thread) }
     }
 }
 
 extern {
     pub unsafe fn rust_raw_thread_start(f: &(~fn())) -> *raw_thread;
-    pub unsafe fn rust_raw_thread_join_delete(thread: *raw_thread);
+    pub unsafe fn rust_raw_thread_join(thread: *raw_thread);
+    pub unsafe fn rust_raw_thread_delete(thread: *raw_thread);
 }