Concurrency-enabled mechanisms for sharing mutable and/or immutable state between tasks.
In this example, a large vector of floats is shared between several tasks. With simple pipes, without Arc, a copy would have to be made for each task.
extern mod std;
use extra::arc;
let numbers=vec::from_fn(100, |ind| (ind as float)*rand::random());
let shared_numbers=arc::Arc::new(numbers);
do 10.times {
let (port, chan) = stream();
chan.send(shared_numbers.clone());
do spawn {
let shared_numbers=port.recv();
let local_numbers=shared_numbers.get();
// Work with the local numbers
}
}
Arc | Immutable Arc An atomically reference counted wrapper for shared immutable state. |
Condvar | As sync::condvar, a mechanism for unlock-and-descheduling and signaling. |
MutexArc | An Arc with mutable data protected by a blocking mutex. |
RWArc | A dual-mode Arc protected by a reader-writer lock. The data can be accessed mutably or immutably, and immutably-accessing tasks may run concurrently. |
RWReadMode | The "read permission" token used for RWArc.write_downgrade(). |
RWWriteMode | The "write permission" token used for RWArc.write_downgrade(). |
Prefix searches with a type followed by a colon (e.g.
fn:
) to restrict the search to a given type.
Accepted types are: fn
, mod
,
struct
(or str
), enum
,
trait
, typedef
(or
tdef
).