|
1.
|
|
|
# Introduction
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-ffi.md:4 src/doc/guide-lifetimes.md:4
src/doc/guide-macros.md:13 src/doc/guide-plugin.md:28
src/doc/guide-tasks.md:4 src/doc/guide-unsafe.md:4
|
|
2.
|
|
|
% The Rust Tasks and Communication Guide
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-tasks.md:2
|
|
3.
|
|
|
Rust provides safe concurrent abstractions through a number of core library primitives. This guide will describe the concurrency model in Rust, how it relates to the Rust type system, and introduce the fundamental library abstractions for constructing concurrent programs.
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-tasks.md:9
|
|
4.
|
|
|
Tasks provide failure isolation and recovery. When a fatal error occurs in Rust code as a result of an explicit call to `panic!()`, an assertion failure, or another invalid operation, the runtime system destroys the entire task. Unlike in languages such as Java and C++, there is no way to `catch` an exception. Instead, tasks may monitor each other to see if they panic.
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-tasks.md:15
|
|
5.
|
|
|
Tasks use Rust's type system to provide strong memory safety guarantees. In particular, the type system guarantees that tasks cannot induce a data race from shared mutable state.
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-tasks.md:19
|
|
6.
|
|
|
# Basics
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-tasks.md:21
|
|
7.
|
|
|
At its simplest, creating a task is a matter of calling the `spawn` function with a closure argument. `spawn` executes the closure in the new task.
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-tasks.md:24
|
|
8.
|
|
|
```{rust} # use std::task::spawn;
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-tasks.md:27 src/doc/guide-tasks.md:74
src/doc/guide-tasks.md:178
|
|
9.
|
|
|
// Print something profound in a different task using a named function fn print_message() { println!("I am running in a different task!"); } spawn(print_message);
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-tasks.md:31
|
|
10.
|
|
|
// Alternatively, use a `proc` expression instead of a named function. // The `proc` expression evaluates to an (unnamed) proc. // That proc will call `println!(...)` when the spawned task runs. spawn(proc() println!("I am also running in a different task!") ); ```
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-tasks.md:37
|