Skip to content

Commit 85890b0

Browse files
committed
---
yaml --- r: 14392 b: refs/heads/try c: 4220dcf h: refs/heads/master v: v3
1 parent e2f92c4 commit 85890b0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+960
-766
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: fbc95ba0184a417ff6d8b2b417f210c960e142cc
5+
refs/heads/try: 4220dcf1e9de2c2d2c329ecefa80108b63a69145
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/doc/tutorial.md

Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2375,10 +2375,10 @@ module `task`. Let's begin with the simplest one, `task::spawn()`:
23752375

23762376
~~~~
23772377
let some_value = 22;
2378-
let child_task = task::spawn {||
2378+
task::spawn {||
23792379
std::io::println("This executes in the child task.");
23802380
std::io::println(#fmt("%d", some_value));
2381-
};
2381+
}
23822382
~~~~
23832383

23842384
The argument to `task::spawn()` is a [unique
@@ -2456,70 +2456,66 @@ let result = comm::recv(port);
24562456
## Creating a task with a bi-directional communication path
24572457

24582458
A very common thing to do is to spawn a child task where the parent
2459-
and child both need to exchange messages with each other. The function
2460-
`task::spawn_connected()` supports this pattern. We'll look briefly at
2461-
how it is used.
2459+
and child both need to exchange messages with each
2460+
other. The function `task::spawn_listener()` supports this pattern. We'll look
2461+
briefly at how it is used.
24622462

2463-
To see how `spawn_connected()` works, we will create a child task
2463+
To see how `spawn_listener()` works, we will create a child task
24642464
which receives `uint` messages, converts them to a string, and sends
24652465
the string in response. The child terminates when `0` is received.
24662466
Here is the function which implements the child task:
24672467

24682468
~~~~
2469-
fn stringifier(from_par: comm::port<uint>,
2470-
to_par: comm::chan<str>) {
2469+
fn stringifier(from_parent: comm::port<uint>,
2470+
to_parent: comm::chan<str>) {
24712471
let value: uint;
24722472
do {
2473-
value = comm::recv(from_par);
2474-
comm::send(to_par, uint::to_str(value, 10u));
2473+
value = comm::recv(from_parent);
2474+
comm::send(to_parent, uint::to_str(value, 10u));
24752475
} while value != 0u;
24762476
}
24772477
24782478
~~~~
2479+
24792480
You can see that the function takes two parameters. The first is a
24802481
port used to receive messages from the parent, and the second is a
24812482
channel used to send messages to the parent. The body itself simply
24822483
loops, reading from the `from_par` port and then sending its response
24832484
to the `to_par` channel. The actual response itself is simply the
24842485
strified version of the received value, `uint::to_str(value)`.
2485-
2486+
24862487
Here is the code for the parent task:
2488+
24872489
~~~~
2488-
# fn stringifier(from_par: comm::port<uint>,
2489-
# to_par: comm::chan<str>) {
2490-
# comm::send(to_par, "22");
2491-
# comm::send(to_par, "23");
2492-
# comm::send(to_par, "0");
2490+
# fn stringifier(from_parent: comm::port<uint>,
2491+
# to_parent: comm::chan<str>) {
2492+
# comm::send(to_parent, "22");
2493+
# comm::send(to_parent, "23");
2494+
# comm::send(to_parent, "0");
24932495
# }
24942496
fn main() {
2495-
let t = task::spawn_connected(stringifier);
2496-
comm::send(t.to_child, 22u);
2497-
assert comm::recv(t.from_child) == "22";
2498-
comm::send(t.to_child, 23u);
2499-
assert comm::recv(t.from_child) == "23";
2500-
comm::send(t.to_child, 0u);
2501-
assert comm::recv(t.from_child) == "0";
2502-
}
2503-
~~~~
2504-
2505-
The call to `spawn_connected()` on the first line will instantiate the
2506-
various ports and channels and startup the child task. The returned
2507-
value, `t`, is a record of type `task::connected_task<uint,str>`. In
2508-
addition to the task id of the child, this record defines two fields,
2509-
`from_child` and `to_child`, which contain the port and channel
2510-
respectively for communicating with the child. Those fields are used
2511-
here to send and receive three messages from the child task.
2512-
2513-
## Joining a task
2514-
2515-
The function `spawn_joinable()` is used to spawn a task that can later
2516-
be joined. This is implemented by having the child task send a message
2517-
when it has completed (either successfully or by failing). Therefore,
2518-
`spawn_joinable()` returns a structure containing both the task ID and
2519-
the port where this message will be sent---this structure type is
2520-
called `task::joinable_task`. The structure can be passed to
2521-
`task::join()`, which simply blocks on the port, waiting to receive
2522-
the message from the child task.
2497+
let from_child = comm::port();
2498+
let to_parent = comm::chan(from_child);
2499+
let to_child = task::spawn_listener {|from_parent|
2500+
stringifier(from_parent, to_parent);
2501+
};
2502+
comm::send(to_child, 22u);
2503+
assert comm::recv(from_child) == "22";
2504+
comm::send(to_child, 23u);
2505+
assert comm::recv(from_child) == "23";
2506+
comm::send(to_child, 0u);
2507+
assert comm::recv(from_child) == "0";
2508+
}
2509+
~~~~
2510+
2511+
The parent first sets up a port to receive data from and a channel
2512+
that the child can use to send data to that port. The call to
2513+
`spawn_listener()` will spawn the child task, providing it with a port
2514+
on which to receive data from its parent, and returning to the parent
2515+
the associated channel. Finally, the closure passed to
2516+
`spawn_listener()` that forms the body of the child task captures the
2517+
`to_parent` channel in its environment, so both parent and child
2518+
can send and receive data to and from the other.
25232519

25242520
## The supervisor relationship
25252521

branches/try/src/comp/driver/rustc.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,6 @@ fn monitor(f: fn~(diagnostic::emitter)) {
143143

144144
alt task::try {||
145145

146-
task::unsupervise();
147-
148146
// The 'diagnostics emitter'. Every error, warning, etc. should
149147
// go through this function.
150148
let demitter = fn@(cmsp: option<(codemap::codemap, codemap::span)>,

branches/try/src/compiletest/procsrv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ fn run(lib_path: str, prog: str, args: [str],
5454
writeclose(pipe_in.out, input);
5555
let p = comm::port();
5656
let ch = comm::chan(p);
57-
task::spawn_sched(1u) {||
57+
task::spawn_sched(task::single_threaded) {||
5858
let errput = readclose(pipe_err.in);
5959
comm::send(ch, (2, errput));
6060
};
61-
task::spawn_sched(1u) {||
61+
task::spawn_sched(task::single_threaded) {||
6262
let output = readclose(pipe_out.in);
6363
comm::send(ch, (1, output));
6464
};

branches/try/src/libcore/comm.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ enum rust_port {}
3535

3636
#[abi = "cdecl"]
3737
native mod rustrt {
38+
fn get_task_id() -> task_id;
3839
fn chan_id_send<T: send>(t: *sys::type_desc,
39-
target_task: task::task, target_port: port_id,
40+
target_task: task_id, target_port: port_id,
4041
data: T) -> ctypes::uintptr_t;
4142

4243
fn new_port(unit_sz: ctypes::size_t) -> *rust_port;
@@ -58,6 +59,7 @@ native mod rusti {
5859
fn call_with_retptr<T: send>(&&f: fn@(*uint)) -> T;
5960
}
6061

62+
type task_id = int;
6163
type port_id = int;
6264

6365
// It's critical that this only have one variant, so it has a record
@@ -75,7 +77,7 @@ type port_id = int;
7577
over other channels."
7678
)]
7779
enum chan<T: send> {
78-
chan_t(task::task, port_id)
80+
chan_t(task_id, port_id)
7981
}
8082

8183
resource port_ptr<T: send>(po: *rust_port) {
@@ -208,7 +210,7 @@ fn peek<T: send>(p: port<T>) -> bool {
208210
port used to construct it."
209211
)]
210212
fn chan<T: send>(p: port<T>) -> chan<T> {
211-
chan_t(task::get_task(), rustrt::get_port_id(***p))
213+
chan_t(rustrt::get_task_id(), rustrt::get_port_id(***p))
212214
}
213215

214216
#[test]

0 commit comments

Comments
 (0)