Skip to content

Change concurrency primitives to standard naming conventions #7978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 28, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions doc/po/tutorial-tasks.md.pot
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ msgstr ""
#. type: Bullet: '* '
#: doc/tutorial-tasks.md:56
msgid ""
"[`extra::arc`] - The ARC (atomically reference counted) type, for safely "
"[`extra::arc`] - The Arc (atomically reference counted) type, for safely "
"sharing immutable data,"
msgstr ""

Expand Down Expand Up @@ -597,7 +597,7 @@ msgstr ""

#. type: Plain text
#: doc/tutorial-tasks.md:338
msgid "## Sharing immutable data without copy: ARC"
msgid "## Sharing immutable data without copy: Arc"
msgstr ""

#. type: Plain text
Expand All @@ -613,18 +613,18 @@ msgstr ""
#: doc/tutorial-tasks.md:347
msgid ""
"To tackle this issue, one can use an Atomically Reference Counted wrapper "
"(`ARC`) as implemented in the `extra` library of Rust. With an ARC, the data "
"will no longer be copied for each task. The ARC acts as a reference to the "
"(`Arc`) as implemented in the `extra` library of Rust. With an Arc, the data "
"will no longer be copied for each task. The Arc acts as a reference to the "
"shared data and only this reference is shared and cloned."
msgstr ""

#. type: Plain text
#: doc/tutorial-tasks.md:355
msgid ""
"Here is a small example showing how to use ARCs. We wish to run concurrently "
"Here is a small example showing how to use Arcs. We wish to run concurrently "
"several computations on a single large vector of floats. Each task needs the "
"full vector to perform its duty. ~~~ # use std::vec; # use std::uint; # use "
"std::rand; use extra::arc::ARC;"
"std::rand; use extra::arc::Arc;"
msgstr ""

#. type: Plain text
Expand All @@ -648,7 +648,7 @@ msgstr ""
#. type: Plain text
#: doc/tutorial-tasks.md:365
#, no-wrap
msgid " let numbers_arc = ARC(numbers);\n"
msgid " let numbers_arc = Arc::new(numbers);\n"
msgstr ""

#. type: Plain text
Expand All @@ -665,7 +665,7 @@ msgstr ""
#, no-wrap
msgid ""
" do spawn {\n"
" let local_arc : ARC<~[float]> = port.recv();\n"
" let local_arc : Arc<~[float]> = port.recv();\n"
" let task_numbers = local_arc.get();\n"
" println(fmt!(\"%u-norm = %?\", num, pnorm(task_numbers, num)));\n"
" }\n"
Expand All @@ -679,31 +679,31 @@ msgstr ""
msgid ""
"The function `pnorm` performs a simple computation on the vector (it "
"computes the sum of its items at the power given as argument and takes the "
"inverse power of this value). The ARC on the vector is created by the line "
"~~~ # use extra::arc::ARC; # use std::vec; # use std::rand; # let numbers = "
"inverse power of this value). The Arc on the vector is created by the line "
"~~~ # use extra::arc::Arc; # use std::vec; # use std::rand; # let numbers = "
"vec::from_fn(1000000, |_| rand::random::<float>()); let "
"numbers_arc=ARC(numbers); ~~~ and a clone of it is sent to each task ~~~ # "
"use extra::arc::ARC; # use std::vec; # use std::rand; # let numbers=vec::"
"numbers_arc=Arc::new(numbers); ~~~ and a clone of it is sent to each task ~~~ # "
"use extra::arc::Arc; # use std::vec; # use std::rand; # let numbers=vec::"
"from_fn(1000000, |_| rand::random::<float>()); # let numbers_arc = "
"ARC(numbers); # let (port, chan) = stream(); chan.send(numbers_arc."
"Arc::new(numbers); # let (port, chan) = stream(); chan.send(numbers_arc."
"clone()); ~~~ copying only the wrapper and not its contents."
msgstr ""

#. type: Plain text
#: doc/tutorial-tasks.md:414
msgid ""
"Each task recovers the underlying data by ~~~ # use extra::arc::ARC; # use "
"Each task recovers the underlying data by ~~~ # use extra::arc::Arc; # use "
"std::vec; # use std::rand; # let numbers=vec::from_fn(1000000, |_| rand::"
"random::<float>()); # let numbers_arc=ARC(numbers); # let (port, chan) = "
"stream(); # chan.send(numbers_arc.clone()); # let local_arc : ARC<~[float]> "
"random::<float>()); # let numbers_arc=Arc::new(numbers); # let (port, chan) = "
"stream(); # chan.send(numbers_arc.clone()); # let local_arc : Arc<~[float]> "
"= port.recv(); let task_numbers = local_arc.get(); ~~~ and can use it as if "
"it were local."
msgstr ""

#. type: Plain text
#: doc/tutorial-tasks.md:416
msgid ""
"The `arc` module also implements ARCs around mutable data that are not "
"The `arc` module also implements Arcs around mutable data that are not "
"covered here."
msgstr ""

Expand Down
34 changes: 17 additions & 17 deletions doc/tutorial-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ concurrency at this writing:
* [`std::pipes`] - The underlying messaging infrastructure,
* [`extra::comm`] - Additional messaging types based on `std::pipes`,
* [`extra::sync`] - More exotic synchronization tools, including locks,
* [`extra::arc`] - The ARC (atomically reference counted) type,
* [`extra::arc`] - The Arc (atomically reference counted) type,
for safely sharing immutable data,
* [`extra::future`] - A type representing values that may be computed concurrently and retrieved at a later time.

Expand Down Expand Up @@ -334,24 +334,24 @@ fn main() {
}
~~~

## Sharing immutable data without copy: ARC
## Sharing immutable data without copy: Arc

To share immutable data between tasks, a first approach would be to only use pipes as we have seen
previously. A copy of the data to share would then be made for each task. In some cases, this would
add up to a significant amount of wasted memory and would require copying the same data more than
necessary.

To tackle this issue, one can use an Atomically Reference Counted wrapper (`ARC`) as implemented in
the `extra` library of Rust. With an ARC, the data will no longer be copied for each task. The ARC
To tackle this issue, one can use an Atomically Reference Counted wrapper (`Arc`) as implemented in
the `extra` library of Rust. With an Arc, the data will no longer be copied for each task. The Arc
acts as a reference to the shared data and only this reference is shared and cloned.

Here is a small example showing how to use ARCs. We wish to run concurrently several computations on
Here is a small example showing how to use Arcs. We wish to run concurrently several computations on
a single large vector of floats. Each task needs the full vector to perform its duty.
~~~
# use std::vec;
# use std::uint;
# use std::rand;
use extra::arc::ARC;
use extra::arc::Arc;

fn pnorm(nums: &~[float], p: uint) -> float {
nums.iter().fold(0.0, |a,b| a+(*b).pow(&(p as float)) ).pow(&(1f / (p as float)))
Expand All @@ -361,14 +361,14 @@ fn main() {
let numbers = vec::from_fn(1000000, |_| rand::random::<float>());
println(fmt!("Inf-norm = %?", *numbers.iter().max().unwrap()));

let numbers_arc = ARC(numbers);
let numbers_arc = Arc::new(numbers);

for uint::range(1,10) |num| {
let (port, chan) = stream();
chan.send(numbers_arc.clone());

do spawn {
let local_arc : ARC<~[float]> = port.recv();
let local_arc : Arc<~[float]> = port.recv();
let task_numbers = local_arc.get();
println(fmt!("%u-norm = %?", num, pnorm(task_numbers, num)));
}
Expand All @@ -377,42 +377,42 @@ fn main() {
~~~

The function `pnorm` performs a simple computation on the vector (it computes the sum of its items
at the power given as argument and takes the inverse power of this value). The ARC on the vector is
at the power given as argument and takes the inverse power of this value). The Arc on the vector is
created by the line
~~~
# use extra::arc::ARC;
# use extra::arc::Arc;
# use std::vec;
# use std::rand;
# let numbers = vec::from_fn(1000000, |_| rand::random::<float>());
let numbers_arc=ARC(numbers);
let numbers_arc=Arc::new(numbers);
~~~
and a clone of it is sent to each task
~~~
# use extra::arc::ARC;
# use extra::arc::Arc;
# use std::vec;
# use std::rand;
# let numbers=vec::from_fn(1000000, |_| rand::random::<float>());
# let numbers_arc = ARC(numbers);
# let numbers_arc = Arc::new(numbers);
# let (port, chan) = stream();
chan.send(numbers_arc.clone());
~~~
copying only the wrapper and not its contents.

Each task recovers the underlying data by
~~~
# use extra::arc::ARC;
# use extra::arc::Arc;
# use std::vec;
# use std::rand;
# let numbers=vec::from_fn(1000000, |_| rand::random::<float>());
# let numbers_arc=ARC(numbers);
# let numbers_arc=Arc::new(numbers);
# let (port, chan) = stream();
# chan.send(numbers_arc.clone());
# let local_arc : ARC<~[float]> = port.recv();
# let local_arc : Arc<~[float]> = port.recv();
let task_numbers = local_arc.get();
~~~
and can use it as if it were local.

The `arc` module also implements ARCs around mutable data that are not covered here.
The `arc` module also implements Arcs around mutable data that are not covered here.

# Handling task failure

Expand Down
Loading