@@ -263,6 +263,7 @@ With `extra::future`, rust has a mechanism for requesting a computation and gett
263263later.
264264
265265The basic example below illustrates this.
266+
266267~~~
267268# fn make_a_sandwich() {};
268269fn fib(n: u64) -> u64 {
@@ -283,6 +284,7 @@ the future needs to be mutable so that it can save the result for next time `get
283284
284285Here is another example showing how futures allow you to background computations. The workload will
285286be distributed on the available cores.
287+
286288~~~
287289# use std::vec;
288290fn partial_sum(start: uint) -> f64 {
@@ -317,6 +319,7 @@ acts as a reference to the shared data and only this reference is shared and clo
317319
318320Here is a small example showing how to use Arcs. We wish to run concurrently several computations on
319321a single large vector of floats. Each task needs the full vector to perform its duty.
322+
320323~~~
321324# use std::vec;
322325# use std::rand;
@@ -348,14 +351,17 @@ fn main() {
348351The function ` pnorm ` performs a simple computation on the vector (it computes the sum of its items
349352at the power given as argument and takes the inverse power of this value). The Arc on the vector is
350353created by the line
354+
351355~~~
352356# use extra::arc::Arc;
353357# use std::vec;
354358# use std::rand;
355359# let numbers = vec::from_fn(1000000, |_| rand::random::<f64>());
356360let numbers_arc=Arc::new(numbers);
357361~~~
362+
358363and a clone of it is sent to each task
364+
359365~~~
360366# use extra::arc::Arc;
361367# use std::vec;
@@ -365,9 +371,11 @@ and a clone of it is sent to each task
365371# let (port, chan) = Chan::new();
366372chan.send(numbers_arc.clone());
367373~~~
374+
368375copying only the wrapper and not its contents.
369376
370377Each task recovers the underlying data by
378+
371379~~~
372380# use extra::arc::Arc;
373381# use std::vec;
@@ -379,6 +387,7 @@ Each task recovers the underlying data by
379387# let local_arc : Arc<~[f64]> = port.recv();
380388let task_numbers = local_arc.get();
381389~~~
390+
382391and can use it as if it were local.
383392
384393The ` arc ` module also implements Arcs around mutable data that are not covered here.
0 commit comments