about summary refs log tree commit diff
path: root/src/libstd/rt
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-07-31 02:10:24 -0700
committerbors <bors@rust-lang.org>2013-07-31 02:10:24 -0700
commit8b7e241e02bb9f82d7b931033afde477d03ff4f2 (patch)
tree84f3b2d5a4f8f81f86b7a04ab937d4a0d18a8366 /src/libstd/rt
parent8a737b502067b1896686bd1f9df7a1446296d80b (diff)
parent33df9fc1d04c224a0c7ecb8d91b75feed75b412c (diff)
downloadrust-8b7e241e02bb9f82d7b931033afde477d03ff4f2.tar.gz
rust-8b7e241e02bb9f82d7b931033afde477d03ff4f2.zip
auto merge of #8139 : brson/rust/rm-old-task-apis, r=pcwalton
This removes a bunch of options from the task builder interface that are irrelevant to the new scheduler and were generally unused anyway. It also bumps the stack size of new scheduler tasks so that there's enough room to run rustc and changes the interface to `Thread` to not implicitly join threads on destruction, but instead require an explicit, and mandatory, call to `join`.
Diffstat (limited to 'src/libstd/rt')
-rw-r--r--src/libstd/rt/comm.rs21
-rw-r--r--src/libstd/rt/mod.rs4
-rw-r--r--src/libstd/rt/sched.rs13
-rw-r--r--src/libstd/rt/task.rs2
-rw-r--r--src/libstd/rt/test.rs4
-rw-r--r--src/libstd/rt/thread.rs19
-rw-r--r--src/libstd/rt/uv/async.rs3
-rw-r--r--src/libstd/rt/uv/net.rs12
-rw-r--r--src/libstd/rt/uv/uvio.rs3
9 files changed, 55 insertions, 26 deletions
diff --git a/src/libstd/rt/comm.rs b/src/libstd/rt/comm.rs
index 6528835c52c..a27ff559b2b 100644
--- a/src/libstd/rt/comm.rs
+++ b/src/libstd/rt/comm.rs
@@ -773,10 +773,11 @@ mod test {
             do run_in_newsched_task {
                 let (port, chan) = oneshot::<int>();
                 let port_cell = Cell::new(port);
-                let _thread = do spawntask_thread {
+                let thread = do spawntask_thread {
                     let _p = port_cell.take();
                 };
                 let _chan = chan;
+                thread.join();
             }
         }
     }
@@ -788,13 +789,15 @@ mod test {
                 let (port, chan) = oneshot::<int>();
                 let chan_cell = Cell::new(chan);
                 let port_cell = Cell::new(port);
-                let _thread1 = do spawntask_thread {
+                let thread1 = do spawntask_thread {
                     let _p = port_cell.take();
                 };
-                let _thread2 = do spawntask_thread {
+                let thread2 = do spawntask_thread {
                     let c = chan_cell.take();
                     c.send(1);
                 };
+                thread1.join();
+                thread2.join();
             }
         }
     }
@@ -806,19 +809,21 @@ mod test {
                 let (port, chan) = oneshot::<int>();
                 let chan_cell = Cell::new(chan);
                 let port_cell = Cell::new(port);
-                let _thread1 = do spawntask_thread {
+                let thread1 = do spawntask_thread {
                     let port_cell = Cell::new(port_cell.take());
                     let res = do spawntask_try {
                         port_cell.take().recv();
                     };
                     assert!(res.is_err());
                 };
-                let _thread2 = do spawntask_thread {
+                let thread2 = do spawntask_thread {
                     let chan_cell = Cell::new(chan_cell.take());
                     do spawntask {
                         chan_cell.take();
                     }
                 };
+                thread1.join();
+                thread2.join();
             }
         }
     }
@@ -830,12 +835,14 @@ mod test {
                 let (port, chan) = oneshot::<~int>();
                 let chan_cell = Cell::new(chan);
                 let port_cell = Cell::new(port);
-                let _thread1 = do spawntask_thread {
+                let thread1 = do spawntask_thread {
                     chan_cell.take().send(~10);
                 };
-                let _thread2 = do spawntask_thread {
+                let thread2 = do spawntask_thread {
                     assert!(port_cell.take().recv() == ~10);
                 };
+                thread1.join();
+                thread2.join();
             }
         }
     }
diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs
index 2ca7d01da49..dc8669b9264 100644
--- a/src/libstd/rt/mod.rs
+++ b/src/libstd/rt/mod.rs
@@ -346,7 +346,9 @@ fn run_(main: ~fn(), use_main_sched: bool) -> int {
     }
 
     // Wait for schedulers
-    { let _threads = threads; }
+    for threads.consume_iter().advance() |thread| {
+        thread.join();
+    }
 
     // Return the exit code
     unsafe {
diff --git a/src/libstd/rt/sched.rs b/src/libstd/rt/sched.rs
index 33cfd69fcd2..98df38f9b1d 100644
--- a/src/libstd/rt/sched.rs
+++ b/src/libstd/rt/sched.rs
@@ -901,10 +901,8 @@ mod test {
                 sched.run();
             };
 
-            // wait for the end
-            let _thread1 = normal_thread;
-            let _thread2 = special_thread;
-
+            normal_thread.join();
+            special_thread.join();
         }
     }
 
@@ -1074,16 +1072,19 @@ mod test {
             sched2.enqueue_task(task2);
 
             let sched1_cell = Cell::new(sched1);
-            let _thread1 = do Thread::start {
+            let thread1 = do Thread::start {
                 let sched1 = sched1_cell.take();
                 sched1.run();
             };
 
             let sched2_cell = Cell::new(sched2);
-            let _thread2 = do Thread::start {
+            let thread2 = do Thread::start {
                 let sched2 = sched2_cell.take();
                 sched2.run();
             };
+
+            thread1.join();
+            thread2.join();
         }
     }
 
diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs
index 8cf864b9222..82d4f8fcc04 100644
--- a/src/libstd/rt/task.rs
+++ b/src/libstd/rt/task.rs
@@ -219,7 +219,7 @@ impl Drop for Task {
 impl Coroutine {
 
     pub fn new(stack_pool: &mut StackPool, start: ~fn()) -> Coroutine {
-        static MIN_STACK_SIZE: uint = 100000; // XXX: Too much stack
+        static MIN_STACK_SIZE: uint = 2000000; // XXX: Too much stack
 
         let start = Coroutine::build_start_wrapper(start);
         let mut stack = stack_pool.take_segment(MIN_STACK_SIZE);
diff --git a/src/libstd/rt/test.rs b/src/libstd/rt/test.rs
index feae8b5ffd8..260903cbcbf 100644
--- a/src/libstd/rt/test.rs
+++ b/src/libstd/rt/test.rs
@@ -125,7 +125,9 @@ pub fn run_in_mt_newsched_task(f: ~fn()) {
         }
 
         // Wait for schedulers
-        let _threads = threads;
+        for threads.consume_iter().advance() |thread| {
+            thread.join();
+        }
     }
 
 }
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);
 }
diff --git a/src/libstd/rt/uv/async.rs b/src/libstd/rt/uv/async.rs
index 47e0a240e45..d0ca38317cb 100644
--- a/src/libstd/rt/uv/async.rs
+++ b/src/libstd/rt/uv/async.rs
@@ -94,12 +94,13 @@ mod test {
             let mut loop_ = Loop::new();
             let watcher = AsyncWatcher::new(&mut loop_, |w, _| w.close(||()) );
             let watcher_cell = Cell::new(watcher);
-            let _thread = do Thread::start {
+            let thread = do Thread::start {
                 let mut watcher = watcher_cell.take();
                 watcher.send();
             };
             loop_.run();
             loop_.close();
+            thread.join();
         }
     }
 }
diff --git a/src/libstd/rt/uv/net.rs b/src/libstd/rt/uv/net.rs
index a039f3ab7ed..8ea4a197269 100644
--- a/src/libstd/rt/uv/net.rs
+++ b/src/libstd/rt/uv/net.rs
@@ -715,7 +715,7 @@ mod test {
                 }
             }
 
-            let _client_thread = do Thread::start {
+            let client_thread = do Thread::start {
                 rtdebug!("starting client thread");
                 let mut loop_ = Loop::new();
                 let mut tcp_watcher = { TcpWatcher::new(&mut loop_) };
@@ -739,6 +739,7 @@ mod test {
             let mut loop_ = loop_;
             loop_.run();
             loop_.close();
+            client_thread.join();
         }
     }
 
@@ -790,7 +791,7 @@ mod test {
                 }
             }
 
-            let _client_thread = do Thread::start {
+            let client_thread = do Thread::start {
                 rtdebug!("starting client thread");
                 let mut loop_ = Loop::new();
                 let mut tcp_watcher = { TcpWatcher::new(&mut loop_) };
@@ -814,6 +815,7 @@ mod test {
             let mut loop_ = loop_;
             loop_.run();
             loop_.close();
+            client_thread.join();
         }
     }
 
@@ -855,7 +857,7 @@ mod test {
                 server.close(||{});
             }
 
-            do Thread::start {
+            let thread = do Thread::start {
                 let mut loop_ = Loop::new();
                 let mut client = UdpWatcher::new(&loop_);
                 assert!(client.bind(client_addr).is_ok());
@@ -873,6 +875,7 @@ mod test {
 
             loop_.run();
             loop_.close();
+            thread.join();
         }
     }
 
@@ -914,7 +917,7 @@ mod test {
                 server.close(||{});
             }
 
-            do Thread::start {
+            let thread = do Thread::start {
                 let mut loop_ = Loop::new();
                 let mut client = UdpWatcher::new(&loop_);
                 assert!(client.bind(client_addr).is_ok());
@@ -932,6 +935,7 @@ mod test {
 
             loop_.run();
             loop_.close();
+            thread.join();
         }
     }
 }
diff --git a/src/libstd/rt/uv/uvio.rs b/src/libstd/rt/uv/uvio.rs
index 5397b5f2c5c..53ccd20186d 100644
--- a/src/libstd/rt/uv/uvio.rs
+++ b/src/libstd/rt/uv/uvio.rs
@@ -222,11 +222,12 @@ mod test_remote {
                 };
                 remote_cell.put_back(remote);
             }
-            let _thread = do Thread::start {
+            let thread = do Thread::start {
                 remote_cell.take().fire();
             };
 
             assert!(tube.recv() == 1);
+            thread.join();
         }
     }
 }