Skip to content

Commit 507ca42

Browse files
author
Olivier Saut
committed
Add an example
1 parent f0f4d2d commit 507ca42

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/libstd/arc.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,33 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
/**
11+
/*!
1212
* Concurrency-enabled mechanisms for sharing mutable and/or immutable state
1313
* between tasks.
14+
*
15+
* # Example
16+
*
17+
* In this example, a large vector of floats is shared between several tasks.
18+
* With simple pipes, without ARC, a copy would have to be made for each task.
19+
*
20+
* ~~~
21+
* # extern mod std;
22+
* # use std::arc;
23+
* let numbers=vec::from_fn(100, |ind| (ind as float)*rand::random());
24+
* let shared_numbers=arc::ARC(numbers);
25+
*
26+
* for 10.times {
27+
* let (port, chan) = stream();
28+
* chan.send(shared_numbers.clone());
29+
*
30+
* do spawn {
31+
* let shared_numbers=port.recv();
32+
* let local_numbers=shared_numbers.get();
33+
*
34+
* // Work with the local numbers
35+
* }
36+
* }
37+
* ~~~
1438
*/
1539

1640
use sync;

0 commit comments

Comments
 (0)