Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
b5d82242
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b5d82242
编写于
4月 04, 2013
作者:
B
bors
浏览文件
操作
浏览文件
下载
差异文件
auto merge of #5713 : brson/rust/tutorial2, r=thestinger
It doesn't quite reflect reality
上级
1dc330c3
679b1dcb
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
28 addition
and
39 deletion
+28
-39
doc/tutorial-tasks.md
doc/tutorial-tasks.md
+28
-39
未找到文件。
doc/tutorial-tasks.md
浏览文件 @
b5d82242
...
...
@@ -2,66 +2,56 @@
# Introduction
The designers of Rust designed the language from the ground up to support pervasive
and safe concurrency through lightweight, memory-isolated tasks and
message passing.
Rust tasks are not the same as traditional threads: rather, they are more like
_green threads_
. The Rust runtime system schedules tasks cooperatively onto a
small number of operating system threads. Because tasks are significantly
Rust provides safe concurrency through a combination
of lightweight, memory-isolated tasks and message passing.
This tutorial 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.
Rust tasks are not the same as traditional threads: rather,
they are considered _green threads_, lightweight units of execution that the Rust
runtime schedules cooperatively onto a small number of operating system threads.
On a multi-core system Rust tasks will be scheduled in parallel by default.
Because tasks are significantly
cheaper to create than traditional threads, Rust can create hundreds of
thousands of concurrent tasks on a typical 32-bit system.
In general, all Rust code executes inside a task, including the
`main`
function.
In order to make efficient use of memory Rust tasks have dynamically sized stacks.
A task begins its life with a small
amount of stack space (currently in the low thousands of bytes, depending on
platform), and acquires more stack as needed.
Unlike in languages such as C, a Rust task cannot accidentally write to
memory beyond the end of the stack, causing crashes or worse.
Tasks provide failure isolation and recovery. When a
n exception
occurs in Rust
code
(
as a result of an explicit call to
`fail!()`
, an assertion failure, or
another invalid operation
)
, the runtime system destroys the entire
Tasks provide failure isolation and recovery. When a
fatal error
occurs in Rust
code as a result of an explicit call to
`fail!()`
, 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 for failure.
Rust tasks have dynamically sized stacks. A task begins its life with a small
amount of stack space (currently in the low thousands of bytes, depending on
platform), and acquires more stack as needed. Unlike in languages such as C, a
Rust task cannot run off the end of the stack. However, tasks do have a stack
budget. If a Rust task exceeds its stack budget, then it will fail safely:
with a checked exception.
Tasks use Rust's type system to provide strong memory safety guarantees. In
particular, the type system guarantees that tasks cannot share mutable state
with each other. Tasks communicate with each other by transferring _owned_
data through the global _exchange heap_.
This tutorial explains the basics of tasks and communication in Rust,
explores some typical patterns in concurrent Rust code, and finally
discusses some of the more unusual synchronization types in the standard
library.
> ***Warning:*** This tutorial is incomplete
## A note about the libraries
While Rust's type system provides the building blocks needed for safe
and efficient tasks, all of the task functionality itself is implemented
in the core and standard libraries, which are still under development
and do not always present a consistent interface.
In particular, there are currently two independent modules that provide a
message passing interface to Rust code:
`core::comm`
and
`core::pipes`
.
`core::comm`
is an older, less efficient system that is being phased out in
favor of
`pipes`
. At some point, we will remove the existing
`core::comm`
API
and move the user-facing portions of
`core::pipes`
to
`core::comm`
. In this
tutorial, we discuss
`pipes`
and ignore the
`comm`
API.
and do not always present a consistent or complete interface.
For your reference, these are the standard modules involved in Rust
concurrency at this writing.
*
[
`core::task`
] - All code relating to tasks and task scheduling
*
[
`core::comm`
] - The
deprecated message passing API
*
[
`core::pipes`
] - The
new message passing infrastructure and API
*
[
`std::comm`
] -
Higher leve
l messaging types based on
`core::pipes`
*
[
`core::comm`
] - The
message passing interface
*
[
`core::pipes`
] - The
underlying messaging infrastructure
*
[
`std::comm`
] -
Additiona
l messaging types based on
`core::pipes`
*
[
`std::sync`
] - More exotic synchronization tools, including locks
*
[
`std::arc`
] - The ARC (atomic reference counted) type, for safely sharing
immutable data
*
[
`std::par`
] - Some basic tools for implementing parallel algorithms
*
[
`std::arc`
] - The ARC (atomically reference counted) type,
for safely sharing immutable data
[
`core::task`
]:
core/task.html
[
`core::comm`
]:
core/comm.html
...
...
@@ -69,7 +59,6 @@ concurrency at this writing.
[
`std::comm`
]:
std/comm.html
[
`std::sync`
]:
std/sync.html
[
`std::arc`
]:
std/arc.html
[
`std::par`
]:
std/par.html
# Basics
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录