Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
c3825cbb
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
c3825cbb
编写于
5月 30, 2014
作者:
J
Jonathan Reem
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove deprecated owned vector from intro.
上级
0033a8b2
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
17 addition
and
13 deletion
+17
-13
src/doc/intro.md
src/doc/intro.md
+17
-13
未找到文件。
src/doc/intro.md
浏览文件 @
c3825cbb
...
...
@@ -198,14 +198,14 @@ Typically, tasks do not share memory but instead communicate amongst each other
```
fn main() {
let numbers =
~
[1,2,3];
let numbers =
vec!
[1,2,3];
let (tx, rx) = channel();
tx.send(numbers);
spawn(proc() {
let numbers = rx.recv();
println!("{}",
numbers[0]
);
println!("{}",
*numbers.get(0)
);
})
}
```
...
...
@@ -237,18 +237,18 @@ try to modify the previous example to continue using the variable `numbers`:
```
ignore
fn main() {
let numbers =
~
[1,2,3];
let numbers =
vec!
[1,2,3];
let (tx, rx) = channel();
tx.send(numbers);
spawn(proc() {
let numbers = rx.recv();
println!("{}", numbers
[0]
);
println!("{}", numbers
.get(0)
);
});
// Try to print a number from the original task
println!("{}",
numbers[0]
);
println!("{}",
*numbers.get(0)
);
}
```
...
...
@@ -256,7 +256,7 @@ This will result an error indicating that the value is no longer in scope:
```
notrust
concurrency.rs:12:20: 12:27 error: use of moved value: 'numbers'
concurrency.rs:12 println!("{}", numbers
[0]
);
concurrency.rs:12 println!("{}", numbers
.get(0)
);
^~~~~~~
```
...
...
@@ -267,7 +267,7 @@ Let's see an example that uses the `clone` method to create copies of the data:
```
fn main() {
let numbers =
~
[1,2,3];
let numbers =
vec!
[1,2,3];
for num in range(0, 3) {
let (tx, rx) = channel();
...
...
@@ -276,7 +276,7 @@ fn main() {
spawn(proc() {
let numbers = rx.recv();
println!("{:d}",
numbers[num as uint]
);
println!("{:d}",
*numbers.get(num as uint)
);
})
}
}
...
...
@@ -301,7 +301,7 @@ extern crate sync;
use sync::Arc;
fn main() {
let numbers =
~
[1,2,3];
let numbers =
vec!
[1,2,3];
let numbers = Arc::new(numbers);
for num in range(0, 3) {
...
...
@@ -310,7 +310,7 @@ fn main() {
spawn(proc() {
let numbers = rx.recv();
println!("{:d}",
numbers[num as uint]
);
println!("{:d}",
*numbers.get(num as uint)
);
})
}
}
...
...
@@ -348,7 +348,7 @@ extern crate sync;
use sync::{Arc, Mutex};
fn main() {
let numbers =
~
[1,2,3];
let numbers =
vec!
[1,2,3];
let numbers_lock = Arc::new(Mutex::new(numbers));
for num in range(0, 3) {
...
...
@@ -360,9 +360,13 @@ fn main() {
// Take the lock, along with exclusive access to the underlying array
let mut numbers = numbers_lock.lock();
numbers[num as uint] += 1;
println!("{}", numbers[num as uint]);
// This is ugly for now, but will be replaced by
// `numbers[num as uint] += 1` in the near future.
// See: https://github.com/mozilla/rust/issues/6515
*numbers.get_mut(num as uint) = *numbers.get_mut(num as uint) + 1;
println!("{}", *numbers.get(num as uint));
// When `numbers` goes out of scope the lock is dropped
})
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录