Skip to content

Commit 39a6c9d

Browse files
committed
Test fallout from std::comm rewrite
1 parent 529e268 commit 39a6c9d

23 files changed

+140
-123
lines changed

doc/tutorial-tasks.md

+19-27
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,16 @@ receiving messages. Pipes are low-level communication building-blocks and so
121121
come in a variety of forms, each one appropriate for a different use case. In
122122
what follows, we cover the most commonly used varieties.
123123

124-
The simplest way to create a pipe is to use the `comm::stream`
124+
The simplest way to create a pipe is to use `Chan::new`
125125
function to create a `(Port, Chan)` pair. In Rust parlance, a *channel*
126126
is a sending endpoint of a pipe, and a *port* is the receiving
127127
endpoint. Consider the following example of calculating two results
128128
concurrently:
129129

130130
~~~~
131131
# use std::task::spawn;
132-
# use std::comm::{stream, Port, Chan};
133132
134-
let (port, chan): (Port<int>, Chan<int>) = stream();
133+
let (port, chan): (Port<int>, Chan<int>) = Chan::new();
135134
136135
do spawn || {
137136
let result = some_expensive_computation();
@@ -150,8 +149,7 @@ stream for sending and receiving integers (the left-hand side of the `let`,
150149
a tuple into its component parts).
151150

152151
~~~~
153-
# use std::comm::{stream, Chan, Port};
154-
let (port, chan): (Port<int>, Chan<int>) = stream();
152+
let (port, chan): (Port<int>, Chan<int>) = Chan::new();
155153
~~~~
156154

157155
The child task will use the channel to send data to the parent task,
@@ -160,9 +158,8 @@ spawns the child task.
160158

161159
~~~~
162160
# use std::task::spawn;
163-
# use std::comm::stream;
164161
# fn some_expensive_computation() -> int { 42 }
165-
# let (port, chan) = stream();
162+
# let (port, chan) = Chan::new();
166163
do spawn || {
167164
let result = some_expensive_computation();
168165
chan.send(result);
@@ -180,25 +177,23 @@ computation, then waits for the child's result to arrive on the
180177
port:
181178

182179
~~~~
183-
# use std::comm::{stream};
184180
# fn some_other_expensive_computation() {}
185-
# let (port, chan) = stream::<int>();
181+
# let (port, chan) = Chan::<int>::new();
186182
# chan.send(0);
187183
some_other_expensive_computation();
188184
let result = port.recv();
189185
~~~~
190186

191-
The `Port` and `Chan` pair created by `stream` enables efficient communication
192-
between a single sender and a single receiver, but multiple senders cannot use
193-
a single `Chan`, and multiple receivers cannot use a single `Port`. What if our
194-
example needed to compute multiple results across a number of tasks? The
195-
following program is ill-typed:
187+
The `Port` and `Chan` pair created by `Chan::new` enables efficient
188+
communication between a single sender and a single receiver, but multiple
189+
senders cannot use a single `Chan`, and multiple receivers cannot use a single
190+
`Port`. What if our example needed to compute multiple results across a number
191+
of tasks? The following program is ill-typed:
196192

197193
~~~ {.xfail-test}
198194
# use std::task::{spawn};
199-
# use std::comm::{stream, Port, Chan};
200195
# fn some_expensive_computation() -> int { 42 }
201-
let (port, chan) = stream();
196+
let (port, chan) = Chan::new();
202197
203198
do spawn {
204199
chan.send(some_expensive_computation());
@@ -216,10 +211,8 @@ Instead we can use a `SharedChan`, a type that allows a single
216211

217212
~~~
218213
# use std::task::spawn;
219-
# use std::comm::{stream, SharedChan};
220214
221-
let (port, chan) = stream();
222-
let chan = SharedChan::new(chan);
215+
let (port, chan) = SharedChan::new();
223216
224217
for init_val in range(0u, 3) {
225218
// Create a new channel handle to distribute to the child task
@@ -238,23 +231,22 @@ Here we transfer ownership of the channel into a new `SharedChan` value. Like
238231
as an *affine* or *linear* type). Unlike with `Chan`, though, the programmer
239232
may duplicate a `SharedChan`, with the `clone()` method. A cloned
240233
`SharedChan` produces a new handle to the same channel, allowing multiple
241-
tasks to send data to a single port. Between `spawn`, `stream` and
234+
tasks to send data to a single port. Between `spawn`, `Chan` and
242235
`SharedChan`, we have enough tools to implement many useful concurrency
243236
patterns.
244237

245238
Note that the above `SharedChan` example is somewhat contrived since
246-
you could also simply use three `stream` pairs, but it serves to
239+
you could also simply use three `Chan` pairs, but it serves to
247240
illustrate the point. For reference, written with multiple streams, it
248241
might look like the example below.
249242

250243
~~~
251244
# use std::task::spawn;
252-
# use std::comm::stream;
253245
# use std::vec;
254246
255247
// Create a vector of ports, one for each child task
256248
let ports = vec::from_fn(3, |init_val| {
257-
let (port, chan) = stream();
249+
let (port, chan) = Chan::new();
258250
do spawn {
259251
chan.send(some_expensive_computation(init_val));
260252
}
@@ -341,7 +333,7 @@ fn main() {
341333
let numbers_arc = Arc::new(numbers);
342334
343335
for num in range(1u, 10) {
344-
let (port, chan) = stream();
336+
let (port, chan) = Chan::new();
345337
chan.send(numbers_arc.clone());
346338
347339
do spawn {
@@ -370,7 +362,7 @@ and a clone of it is sent to each task
370362
# use std::rand;
371363
# let numbers=vec::from_fn(1000000, |_| rand::random::<f64>());
372364
# let numbers_arc = Arc::new(numbers);
373-
# let (port, chan) = stream();
365+
# let (port, chan) = Chan::new();
374366
chan.send(numbers_arc.clone());
375367
~~~
376368
copying only the wrapper and not its contents.
@@ -382,7 +374,7 @@ Each task recovers the underlying data by
382374
# use std::rand;
383375
# let numbers=vec::from_fn(1000000, |_| rand::random::<f64>());
384376
# let numbers_arc=Arc::new(numbers);
385-
# let (port, chan) = stream();
377+
# let (port, chan) = Chan::new();
386378
# chan.send(numbers_arc.clone());
387379
# let local_arc : Arc<~[f64]> = port.recv();
388380
let task_numbers = local_arc.get();
@@ -499,7 +491,7 @@ Here is the code for the parent task:
499491
# }
500492
# fn main() {
501493
502-
let (from_child, to_child) = DuplexStream();
494+
let (from_child, to_child) = DuplexStream::new();
503495
504496
do spawn {
505497
stringifier(&to_child);

src/libextra/arc.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -635,9 +635,8 @@ mod tests {
635635
})
636636
}
637637

638-
let mut c = Some(c);
639638
arc.access_cond(|state, cond| {
640-
c.take_unwrawp().send(());
639+
c.send(());
641640
assert!(!*state);
642641
while !*state {
643642
cond.wait();

src/libextra/sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,6 @@ mod tests {
950950
let mi = m2.clone();
951951
// spawn sibling task
952952
do task::spawn { // linked
953-
let mut c = Some(c);
954953
mi.lock_cond(|cond| {
955954
c.send(()); // tell sibling to go ahead
956955
(|| {
@@ -994,6 +993,7 @@ mod tests {
994993
})
995994
}
996995
#[test]
996+
#[ignore(reason = "linked failure?")]
997997
fn test_mutex_different_conds() {
998998
let result = do task::try {
999999
let m = Mutex::new_with_condvars(2);

src/librustuv/net.rs

+19-20
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,6 @@ impl Drop for UdpWatcher {
646646

647647
#[cfg(test)]
648648
mod test {
649-
use std::comm::oneshot;
650649
use std::rt::test::*;
651650
use std::rt::rtio::{RtioTcpStream, RtioTcpListener, RtioTcpAcceptor,
652651
RtioUdpSocket};
@@ -689,7 +688,7 @@ mod test {
689688
690689
#[test]
691690
fn listen_ip4() {
692-
let (port, chan) = oneshot();
691+
let (port, chan) = Chan::new();
693692
let addr = next_test_ip4();
694693
695694
do spawn {
@@ -725,7 +724,7 @@ mod test {
725724
726725
#[test]
727726
fn listen_ip6() {
728-
let (port, chan) = oneshot();
727+
let (port, chan) = Chan::new();
729728
let addr = next_test_ip6();
730729
731730
do spawn {
@@ -761,7 +760,7 @@ mod test {
761760
762761
#[test]
763762
fn udp_recv_ip4() {
764-
let (port, chan) = oneshot();
763+
let (port, chan) = Chan::new();
765764
let client = next_test_ip4();
766765
let server = next_test_ip4();
767766
@@ -793,7 +792,7 @@ mod test {
793792
794793
#[test]
795794
fn udp_recv_ip6() {
796-
let (port, chan) = oneshot();
795+
let (port, chan) = Chan::new();
797796
let client = next_test_ip6();
798797
let server = next_test_ip6();
799798
@@ -828,7 +827,7 @@ mod test {
828827
use std::rt::rtio::*;
829828
let addr = next_test_ip4();
830829
static MAX: uint = 5000;
831-
let (port, chan) = oneshot();
830+
let (port, chan) = Chan::new();
832831
833832
do spawn {
834833
let listener = TcpListener::bind(local_loop(), addr).unwrap();
@@ -865,7 +864,7 @@ mod test {
865864
fn test_udp_twice() {
866865
let server_addr = next_test_ip4();
867866
let client_addr = next_test_ip4();
868-
let (port, chan) = oneshot();
867+
let (port, chan) = Chan::new();
869868
870869
do spawn {
871870
let mut client = UdpWatcher::bind(local_loop(), client_addr).unwrap();
@@ -896,8 +895,8 @@ mod test {
896895
let client_in_addr = next_test_ip4();
897896
static MAX: uint = 500_000;
898897
899-
let (p1, c1) = oneshot();
900-
let (p2, c2) = oneshot();
898+
let (p1, c1) = Chan::new();
899+
let (p2, c2) = Chan::new();
901900
902901
do spawn {
903902
let l = local_loop();
@@ -953,12 +952,12 @@ mod test {
953952
#[test]
954953
fn test_read_and_block() {
955954
let addr = next_test_ip4();
956-
let (port, chan) = oneshot();
955+
let (port, chan) = Chan::new();
957956
958957
do spawn {
959958
let listener = TcpListener::bind(local_loop(), addr).unwrap();
960959
let mut acceptor = listener.listen().unwrap();
961-
let (port2, chan2) = stream();
960+
let (port2, chan2) = Chan::new();
962961
chan.send(port2);
963962
let mut stream = acceptor.accept().unwrap();
964963
let mut buf = [0, .. 2048];
@@ -1026,7 +1025,7 @@ mod test {
10261025
// thread, close itself, and then come back to the last thread.
10271026
#[test]
10281027
fn test_homing_closes_correctly() {
1029-
let (port, chan) = oneshot();
1028+
let (port, chan) = Chan::new();
10301029
10311030
do task::spawn_sched(task::SingleThreaded) {
10321031
let listener = UdpWatcher::bind(local_loop(), next_test_ip4()).unwrap();
@@ -1048,9 +1047,9 @@ mod test {
10481047
use std::rt::sched::{Shutdown, TaskFromFriend};
10491048
use std::rt::sleeper_list::SleeperList;
10501049
use std::rt::task::Task;
1051-
use std::rt::task::UnwindResult;
10521050
use std::rt::thread::Thread;
10531051
use std::rt::deque::BufferPool;
1052+
use std::task::TaskResult;
10541053
use std::unstable::run_in_bare_thread;
10551054
use uvio::UvEventLoop;
10561055
@@ -1072,12 +1071,12 @@ mod test {
10721071
let handle2 = sched2.make_handle();
10731072
let tasksFriendHandle = sched2.make_handle();
10741073
1075-
let on_exit: proc(UnwindResult) = proc(exit_status) {
1074+
let on_exit: proc(TaskResult) = proc(exit_status) {
10761075
let mut handle1 = handle1;
10771076
let mut handle2 = handle2;
10781077
handle1.send(Shutdown);
10791078
handle2.send(Shutdown);
1080-
assert!(exit_status.is_success());
1079+
assert!(exit_status.is_ok());
10811080
};
10821081
10831082
unsafe fn local_io() -> &'static mut IoFactory {
@@ -1148,7 +1147,7 @@ mod test {
11481147
11491148
#[should_fail] #[test]
11501149
fn tcp_stream_fail_cleanup() {
1151-
let (port, chan) = oneshot();
1150+
let (port, chan) = Chan::new();
11521151
let addr = next_test_ip4();
11531152
11541153
do spawn {
@@ -1172,7 +1171,7 @@ mod test {
11721171
#[should_fail] #[test]
11731172
fn udp_fail_other_task() {
11741173
let addr = next_test_ip4();
1175-
let (port, chan) = oneshot();
1174+
let (port, chan) = Chan::new();
11761175
11771176
// force the handle to be created on a different scheduler, failure in
11781177
// the original task will force a homing operation back to this
@@ -1190,7 +1189,7 @@ mod test {
11901189
#[test]
11911190
#[ignore(reason = "linked failure")]
11921191
fn linked_failure1() {
1193-
let (port, chan) = oneshot();
1192+
let (port, chan) = Chan::new();
11941193
let addr = next_test_ip4();
11951194
11961195
do spawn {
@@ -1208,7 +1207,7 @@ mod test {
12081207
#[test]
12091208
#[ignore(reason = "linked failure")]
12101209
fn linked_failure2() {
1211-
let (port, chan) = oneshot();
1210+
let (port, chan) = Chan::new();
12121211
let addr = next_test_ip4();
12131212
12141213
do spawn {
@@ -1229,7 +1228,7 @@ mod test {
12291228
#[test]
12301229
#[ignore(reason = "linked failure")]
12311230
fn linked_failure3() {
1232-
let (port, chan) = stream();
1231+
let (port, chan) = Chan::new();
12331232
let addr = next_test_ip4();
12341233

12351234
do spawn {

src/librustuv/pipe.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ impl HomingIO for PipeAcceptor {
231231

232232
#[cfg(test)]
233233
mod tests {
234-
use std::comm::oneshot;
235234
use std::rt::rtio::{RtioUnixListener, RtioUnixAcceptor, RtioPipe};
236235
use std::rt::test::next_test_unix;
237236

@@ -274,7 +273,7 @@ mod tests {
274273
fn connect() {
275274
let path = next_test_unix();
276275
let path2 = path.clone();
277-
let (port, chan) = oneshot();
276+
let (port, chan) = Chan::new();
278277

279278
do spawn {
280279
let p = PipeListener::bind(local_loop(), &path2.to_c_str()).unwrap();
@@ -298,7 +297,7 @@ mod tests {
298297
fn connect_fail() {
299298
let path = next_test_unix();
300299
let path2 = path.clone();
301-
let (port, chan) = oneshot();
300+
let (port, chan) = Chan::new();
302301

303302
do spawn {
304303
let p = PipeListener::bind(local_loop(), &path2.to_c_str()).unwrap();

src/librustuv/signal.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,11 @@ mod test {
7878
use super::*;
7979
use super::super::local_loop;
8080
use std::io::signal;
81-
use std::comm::{SharedChan, stream};
8281

8382
#[test]
8483
fn closing_channel_during_drop_doesnt_kill_everything() {
8584
// see issue #10375, relates to timers as well.
86-
let (port, chan) = stream();
87-
let chan = SharedChan::new(chan);
85+
let (port, chan) = SharedChan::new();
8886
let _signal = SignalWatcher::new(local_loop(), signal::Interrupt,
8987
chan);
9088

0 commit comments

Comments
 (0)