Skip to content

Commit 8b7e241

Browse files
committed
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`.
2 parents 8a737b5 + 33df9fc commit 8b7e241

20 files changed

+89
-244
lines changed

src/libextra/sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ mod tests {
882882
fn test_sem_runtime_friendly_blocking() {
883883
// Force the runtime to schedule two threads on the same sched_loop.
884884
// When one blocks, it should schedule the other one.
885-
do task::spawn_sched(task::ManualThreads(1)) {
885+
do task::spawn_sched(task::SingleThreaded) {
886886
let s = ~Semaphore::new(1);
887887
let s2 = ~s.clone();
888888
let (p,c) = comm::stream();

src/libstd/rt/comm.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -773,10 +773,11 @@ mod test {
773773
do run_in_newsched_task {
774774
let (port, chan) = oneshot::<int>();
775775
let port_cell = Cell::new(port);
776-
let _thread = do spawntask_thread {
776+
let thread = do spawntask_thread {
777777
let _p = port_cell.take();
778778
};
779779
let _chan = chan;
780+
thread.join();
780781
}
781782
}
782783
}
@@ -788,13 +789,15 @@ mod test {
788789
let (port, chan) = oneshot::<int>();
789790
let chan_cell = Cell::new(chan);
790791
let port_cell = Cell::new(port);
791-
let _thread1 = do spawntask_thread {
792+
let thread1 = do spawntask_thread {
792793
let _p = port_cell.take();
793794
};
794-
let _thread2 = do spawntask_thread {
795+
let thread2 = do spawntask_thread {
795796
let c = chan_cell.take();
796797
c.send(1);
797798
};
799+
thread1.join();
800+
thread2.join();
798801
}
799802
}
800803
}
@@ -806,19 +809,21 @@ mod test {
806809
let (port, chan) = oneshot::<int>();
807810
let chan_cell = Cell::new(chan);
808811
let port_cell = Cell::new(port);
809-
let _thread1 = do spawntask_thread {
812+
let thread1 = do spawntask_thread {
810813
let port_cell = Cell::new(port_cell.take());
811814
let res = do spawntask_try {
812815
port_cell.take().recv();
813816
};
814817
assert!(res.is_err());
815818
};
816-
let _thread2 = do spawntask_thread {
819+
let thread2 = do spawntask_thread {
817820
let chan_cell = Cell::new(chan_cell.take());
818821
do spawntask {
819822
chan_cell.take();
820823
}
821824
};
825+
thread1.join();
826+
thread2.join();
822827
}
823828
}
824829
}
@@ -830,12 +835,14 @@ mod test {
830835
let (port, chan) = oneshot::<~int>();
831836
let chan_cell = Cell::new(chan);
832837
let port_cell = Cell::new(port);
833-
let _thread1 = do spawntask_thread {
838+
let thread1 = do spawntask_thread {
834839
chan_cell.take().send(~10);
835840
};
836-
let _thread2 = do spawntask_thread {
841+
let thread2 = do spawntask_thread {
837842
assert!(port_cell.take().recv() == ~10);
838843
};
844+
thread1.join();
845+
thread2.join();
839846
}
840847
}
841848
}

src/libstd/rt/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,9 @@ fn run_(main: ~fn(), use_main_sched: bool) -> int {
346346
}
347347

348348
// Wait for schedulers
349-
{ let _threads = threads; }
349+
for threads.consume_iter().advance() |thread| {
350+
thread.join();
351+
}
350352

351353
// Return the exit code
352354
unsafe {

src/libstd/rt/sched.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -901,10 +901,8 @@ mod test {
901901
sched.run();
902902
};
903903

904-
// wait for the end
905-
let _thread1 = normal_thread;
906-
let _thread2 = special_thread;
907-
904+
normal_thread.join();
905+
special_thread.join();
908906
}
909907
}
910908

@@ -1074,16 +1072,19 @@ mod test {
10741072
sched2.enqueue_task(task2);
10751073

10761074
let sched1_cell = Cell::new(sched1);
1077-
let _thread1 = do Thread::start {
1075+
let thread1 = do Thread::start {
10781076
let sched1 = sched1_cell.take();
10791077
sched1.run();
10801078
};
10811079

10821080
let sched2_cell = Cell::new(sched2);
1083-
let _thread2 = do Thread::start {
1081+
let thread2 = do Thread::start {
10841082
let sched2 = sched2_cell.take();
10851083
sched2.run();
10861084
};
1085+
1086+
thread1.join();
1087+
thread2.join();
10871088
}
10881089
}
10891090

src/libstd/rt/task.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl Drop for Task {
219219
impl Coroutine {
220220

221221
pub fn new(stack_pool: &mut StackPool, start: ~fn()) -> Coroutine {
222-
static MIN_STACK_SIZE: uint = 100000; // XXX: Too much stack
222+
static MIN_STACK_SIZE: uint = 2000000; // XXX: Too much stack
223223

224224
let start = Coroutine::build_start_wrapper(start);
225225
let mut stack = stack_pool.take_segment(MIN_STACK_SIZE);

src/libstd/rt/test.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ pub fn run_in_mt_newsched_task(f: ~fn()) {
125125
}
126126

127127
// Wait for schedulers
128-
let _threads = threads;
128+
for threads.consume_iter().advance() |thread| {
129+
thread.join();
130+
}
129131
}
130132

131133
}

src/libstd/rt/thread.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ type raw_thread = libc::c_void;
1616

1717
pub struct Thread {
1818
main: ~fn(),
19-
raw_thread: *raw_thread
19+
raw_thread: *raw_thread,
20+
joined: bool
2021
}
2122

2223
impl Thread {
@@ -27,18 +28,28 @@ impl Thread {
2728
let raw = substart(&main);
2829
Thread {
2930
main: main,
30-
raw_thread: raw
31+
raw_thread: raw,
32+
joined: false
3133
}
3234
}
35+
36+
pub fn join(self) {
37+
assert!(!self.joined);
38+
let mut this = self;
39+
unsafe { rust_raw_thread_join(this.raw_thread); }
40+
this.joined = true;
41+
}
3342
}
3443

3544
impl Drop for Thread {
3645
fn drop(&self) {
37-
unsafe { rust_raw_thread_join_delete(self.raw_thread) }
46+
assert!(self.joined);
47+
unsafe { rust_raw_thread_delete(self.raw_thread) }
3848
}
3949
}
4050

4151
extern {
4252
pub unsafe fn rust_raw_thread_start(f: &(~fn())) -> *raw_thread;
43-
pub unsafe fn rust_raw_thread_join_delete(thread: *raw_thread);
53+
pub unsafe fn rust_raw_thread_join(thread: *raw_thread);
54+
pub unsafe fn rust_raw_thread_delete(thread: *raw_thread);
4455
}

src/libstd/rt/uv/async.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,13 @@ mod test {
9494
let mut loop_ = Loop::new();
9595
let watcher = AsyncWatcher::new(&mut loop_, |w, _| w.close(||()) );
9696
let watcher_cell = Cell::new(watcher);
97-
let _thread = do Thread::start {
97+
let thread = do Thread::start {
9898
let mut watcher = watcher_cell.take();
9999
watcher.send();
100100
};
101101
loop_.run();
102102
loop_.close();
103+
thread.join();
103104
}
104105
}
105106
}

src/libstd/rt/uv/net.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ mod test {
715715
}
716716
}
717717
718-
let _client_thread = do Thread::start {
718+
let client_thread = do Thread::start {
719719
rtdebug!("starting client thread");
720720
let mut loop_ = Loop::new();
721721
let mut tcp_watcher = { TcpWatcher::new(&mut loop_) };
@@ -739,6 +739,7 @@ mod test {
739739
let mut loop_ = loop_;
740740
loop_.run();
741741
loop_.close();
742+
client_thread.join();
742743
}
743744
}
744745
@@ -790,7 +791,7 @@ mod test {
790791
}
791792
}
792793
793-
let _client_thread = do Thread::start {
794+
let client_thread = do Thread::start {
794795
rtdebug!("starting client thread");
795796
let mut loop_ = Loop::new();
796797
let mut tcp_watcher = { TcpWatcher::new(&mut loop_) };
@@ -814,6 +815,7 @@ mod test {
814815
let mut loop_ = loop_;
815816
loop_.run();
816817
loop_.close();
818+
client_thread.join();
817819
}
818820
}
819821
@@ -855,7 +857,7 @@ mod test {
855857
server.close(||{});
856858
}
857859
858-
do Thread::start {
860+
let thread = do Thread::start {
859861
let mut loop_ = Loop::new();
860862
let mut client = UdpWatcher::new(&loop_);
861863
assert!(client.bind(client_addr).is_ok());
@@ -873,6 +875,7 @@ mod test {
873875
874876
loop_.run();
875877
loop_.close();
878+
thread.join();
876879
}
877880
}
878881
@@ -914,7 +917,7 @@ mod test {
914917
server.close(||{});
915918
}
916919
917-
do Thread::start {
920+
let thread = do Thread::start {
918921
let mut loop_ = Loop::new();
919922
let mut client = UdpWatcher::new(&loop_);
920923
assert!(client.bind(client_addr).is_ok());
@@ -932,6 +935,7 @@ mod test {
932935

933936
loop_.run();
934937
loop_.close();
938+
thread.join();
935939
}
936940
}
937941
}

src/libstd/rt/uv/uvio.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,12 @@ mod test_remote {
222222
};
223223
remote_cell.put_back(remote);
224224
}
225-
let _thread = do Thread::start {
225+
let thread = do Thread::start {
226226
remote_cell.take().fire();
227227
};
228228

229229
assert!(tube.recv() == 1);
230+
thread.join();
230231
}
231232
}
232233
}

0 commit comments

Comments
 (0)