Skip to content

Commit 8d9da81

Browse files
committed
---
yaml --- r: 30901 b: refs/heads/incoming c: 6d97c41 h: refs/heads/master i: 30899: 2b9618c v: v3
1 parent 97180bb commit 8d9da81

File tree

2 files changed

+63
-10
lines changed

2 files changed

+63
-10
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: affa3880debc91adde71e78345c30ce2044f8cef
9+
refs/heads/incoming: 6d97c4177c1b3f158246eaedccf99442876e5ee2
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/doc/tutorial-tasks.md

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,68 @@
22

33
# Introduction
44

5-
Rust supports a system of lightweight tasks, similar to what is found
6-
in Erlang or other actor systems. Rust tasks communicate via messages
7-
and do not share data. However, it is possible to send data without
8-
copying it by making use of [the exchange heap](#unique-boxes), which
9-
allow the sending task to release ownership of a value, so that the
10-
receiving task can keep on using it.
11-
12-
> ***Note:*** As Rust evolves, we expect the task API to grow and
13-
> change somewhat. The tutorial documents the API as it exists today.
5+
Rust supports concurrency and parallelism through lightweight tasks.
6+
Rust tasks are significantly cheaper to create than traditional
7+
threads, with a typical 32-bit system able to run hundreds of
8+
thousands simultaneously. Tasks in Rust are what are often referred to
9+
as _green threads_, cooperatively scheduled by the Rust runtime onto a
10+
small number of operating system threads.
11+
12+
Tasks provide failure isolation and recovery. When an exception occurs
13+
in rust code (either by calling `fail` explicitly or by otherwise performing
14+
an invalid operation) the entire task is destroyed - there is no way
15+
to `catch` an exception as in other languages. Instead tasks may monitor
16+
each other to detect when failure has occurred.
17+
18+
Rust tasks have dynamically sized stacks. When a task is first created
19+
it starts off with a small amount of stack (in the hundreds to
20+
low thousands of bytes, depending on plattform), and more stack is
21+
added as needed. A Rust task will never run off the end of the stack as
22+
is possible in many other languages, but they do have a stack budget,
23+
and if a Rust task exceeds its stack budget then it will fail safely.
24+
25+
Tasks make use of Rust's type system to provide strong memory safety
26+
guarantees, disallowing shared mutable state. Communication between
27+
tasks is facilitated by the transfer of _owned_ data through the
28+
global _exchange heap_.
29+
30+
This tutorial will explain the basics of tasks and communication in Rust,
31+
explore some typical patterns in concurrent Rust code, and finally
32+
discuss some of the more exotic synchronization types in the standard
33+
library.
34+
35+
# A note about the libraries
36+
37+
While Rust's type system provides the building blocks needed for safe
38+
and efficient tasks, all of the task functionality itself is implemented
39+
in the core and standard libraries, which are still under development
40+
and do not always present a nice programming interface.
41+
42+
In particular, there are currently two independent modules that provide
43+
a message passing interface to Rust code: `core::comm` and `core::pipes`.
44+
`core::comm` is an older, less efficient system that is being phased out
45+
in favor of `pipes`. At some point the existing `core::comm` API will
46+
be romoved and the user-facing portions of `core::pipes` will be moved
47+
to `core::comm`. In this tutorial we will discuss `pipes` and ignore
48+
the `comm` API.
49+
50+
For your reference, these are the standard modules involved in Rust
51+
concurrency at the moment.
52+
53+
* [`core::task`] - All code relating to tasks and task scheduling
54+
* [`core::comm`] - The deprecated message passing API
55+
* [`core::pipes`] - The new message passing infrastructure and API
56+
* [`std::comm`] - Higher level messaging types based on `core::pipes`
57+
* [`std::sync`] - More exotic synchronization tools, including locks
58+
* [`std::arc`] - The ARC type, for safely sharing immutable data
59+
60+
[`core::task`]: core/task.html
61+
[`core::comm`]: core/comm.html
62+
[`core::pipes`]: core/pipes.html
63+
[`std::comm`]: std/comm.html
64+
[`std::sync`]: std/sync.html
65+
[`std::arc`]: std/arc.html
66+
1467

1568
# Spawning a task
1669

0 commit comments

Comments
 (0)