Skip to content

Commit 2a6c5cd

Browse files
committed
---
yaml --- r: 141015 b: refs/heads/try2 c: a9c465c h: refs/heads/master i: 141013: 37f57a2 141011: 810785c 141007: daea759 v: v3
1 parent 269ec7e commit 2a6c5cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1878
-4959
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 3ee479f3e98474cd8125432f7a0c5c18bc2bd342
8+
refs/heads/try2: a9c465ce1f1caaae58a31c57f665217ee58bb876
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/doc/tutorial-tasks.md

Lines changed: 13 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,22 @@ in the core and standard libraries, which are still under development
4343
and do not always present a consistent or complete interface.
4444

4545
For your reference, these are the standard modules involved in Rust
46-
concurrency at this writing:
46+
concurrency at this writing.
4747

48-
* [`core::task`] - All code relating to tasks and task scheduling,
49-
* [`core::comm`] - The message passing interface,
50-
* [`core::pipes`] - The underlying messaging infrastructure,
51-
* [`std::comm`] - Additional messaging types based on `core::pipes`,
52-
* [`std::sync`] - More exotic synchronization tools, including locks,
48+
* [`core::task`] - All code relating to tasks and task scheduling
49+
* [`core::comm`] - The message passing interface
50+
* [`core::pipes`] - The underlying messaging infrastructure
51+
* [`std::comm`] - Additional messaging types based on `core::pipes`
52+
* [`std::sync`] - More exotic synchronization tools, including locks
5353
* [`std::arc`] - The ARC (atomically reference counted) type,
54-
for safely sharing immutable data,
55-
* [`std::future`] - A type representing values that may be computed concurrently and retrieved at a later time.
54+
for safely sharing immutable data
5655

5756
[`core::task`]: core/task.html
5857
[`core::comm`]: core/comm.html
5958
[`core::pipes`]: core/pipes.html
6059
[`std::comm`]: std/comm.html
6160
[`std::sync`]: std/sync.html
6261
[`std::arc`]: std/arc.html
63-
[`std::future`]: std/future.html
6462

6563
# Basics
6664

@@ -72,7 +70,7 @@ closure in the new task.
7270

7371
~~~~
7472
# use core::io::println;
75-
# use core::task::spawn;
73+
use core::task::spawn;
7674
7775
// Print something profound in a different task using a named function
7876
fn print_message() { println("I am running in a different task!"); }
@@ -147,8 +145,8 @@ endpoint. Consider the following example of calculating two results
147145
concurrently:
148146

149147
~~~~
150-
# use core::task::spawn;
151-
# use core::comm::{stream, Port, Chan};
148+
use core::task::spawn;
149+
use core::comm::{stream, Port, Chan};
152150
153151
let (port, chan): (Port<int>, Chan<int>) = stream();
154152
@@ -235,7 +233,7 @@ Instead we can use a `SharedChan`, a type that allows a single
235233

236234
~~~
237235
# use core::task::spawn;
238-
# use core::comm::{stream, SharedChan};
236+
use core::comm::{stream, SharedChan};
239237
240238
let (port, chan) = stream();
241239
let chan = SharedChan::new(chan);
@@ -284,51 +282,6 @@ let result = ports.foldl(0, |accum, port| *accum + port.recv() );
284282
# fn some_expensive_computation(_i: uint) -> int { 42 }
285283
~~~
286284

287-
## Futures
288-
With `std::future`, rust has a mechanism for requesting a computation and getting the result
289-
later.
290-
291-
The basic example below illustrates this.
292-
~~~
293-
# fn make_a_sandwich() {};
294-
fn fib(n: uint) -> uint {
295-
// lengthy computation returning an uint
296-
12586269025
297-
}
298-
299-
let mut delayed_fib = std::future::spawn (|| fib(50) );
300-
make_a_sandwich();
301-
println(fmt!("fib(50) = %?", delayed_fib.get()))
302-
~~~
303-
304-
The call to `future::spawn` returns immediately a `future` object regardless of how long it
305-
takes to run `fib(50)`. You can then make yourself a sandwich while the computation of `fib` is
306-
running. The result of the execution of the method is obtained by calling `get` on the future.
307-
This call will block until the value is available (*i.e.* the computation is complete). Note that
308-
the future needs to be mutable so that it can save the result for next time `get` is called.
309-
310-
Here is another example showing how futures allow you to background computations. The workload will
311-
be distributed on the available cores.
312-
~~~
313-
fn partial_sum(start: uint) -> f64 {
314-
let mut local_sum = 0f64;
315-
for uint::range(start*100000, (start+1)*100000) |num| {
316-
local_sum += (num as f64 + 1.0).pow(-2.0);
317-
}
318-
local_sum
319-
}
320-
321-
fn main() {
322-
let mut futures = vec::from_fn(1000, |ind| do std::future::spawn { partial_sum(ind) });
323-
324-
let mut final_res = 0f64;
325-
for futures.each_mut |ft| {
326-
final_res += ft.get();
327-
}
328-
println(fmt!("π^2/6 is not far from : %?", final_res));
329-
}
330-
~~~
331-
332285
# Handling task failure
333286

334287
Rust has a built-in mechanism for raising exceptions. The `fail!()` macro
@@ -410,8 +363,8 @@ either task fails, it kills the other one.
410363
~~~
411364
# fn sleep_forever() { loop { task::yield() } }
412365
# do task::try {
413-
do spawn {
414-
do spawn {
366+
do task::spawn {
367+
do task::spawn {
415368
fail!(); // All three tasks will fail.
416369
}
417370
sleep_forever(); // Will get woken up by force, then fail

branches/try2/src/libcore/bool.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ pub fn is_false(v: bool) -> bool { !v }
4949
/// Parse logic value from `s`
5050
impl FromStr for bool {
5151
fn from_str(s: &str) -> Option<bool> {
52-
match s {
53-
"true" => Some(true),
54-
"false" => Some(false),
55-
_ => None,
52+
if s == "true" {
53+
Some(true)
54+
} else if s == "false" {
55+
Some(false)
56+
} else {
57+
None
5658
}
5759
}
5860
}

0 commit comments

Comments
 (0)