auto merge of #14746 : alexcrichton/rust/libsync, r=brson
This commit is the final step in the libstd facade, #13851. The purpose of this commit is to move libsync underneath the standard library, behind the facade. This will allow core primitives like channels, queues, and atomics to all live in the same location. There were a few notable changes and a few breaking changes as part of this movement: * The `Vec` and `String` types are reexported at the top level of libcollections * The `unreachable!()` macro was copied to libcore * The `std::rt::thread` module was moved to librustrt, but it is still reexported at the same location. * The `std::comm` module was moved to libsync * The `sync::comm` module was moved under `sync::comm`, and renamed to `duplex`. It is now a private module with types/functions being reexported under `sync::comm`. This is a breaking change for any existing users of duplex streams. * All concurrent queues/deques were moved directly under libsync. They are also all marked with #![experimental] for now if they are public. * The `task_pool` and `future` modules no longer live in libsync, but rather live under `std::sync`. They will forever live at this location, but they may move to libsync if the `std::task` module moves as well. [breaking-change]
This commit is contained in:
commit
f9260d41d6
61 changed files with 383 additions and 362 deletions
|
|
@ -269,7 +269,7 @@ later.
|
|||
The basic example below illustrates this.
|
||||
|
||||
~~~
|
||||
extern crate sync;
|
||||
use std::sync::Future;
|
||||
|
||||
# fn main() {
|
||||
# fn make_a_sandwich() {};
|
||||
|
|
@ -278,7 +278,7 @@ fn fib(n: u64) -> u64 {
|
|||
12586269025
|
||||
}
|
||||
|
||||
let mut delayed_fib = sync::Future::spawn(proc() fib(50));
|
||||
let mut delayed_fib = Future::spawn(proc() fib(50));
|
||||
make_a_sandwich();
|
||||
println!("fib(50) = {}", delayed_fib.get())
|
||||
# }
|
||||
|
|
@ -294,7 +294,7 @@ Here is another example showing how futures allow you to background computations
|
|||
be distributed on the available cores.
|
||||
|
||||
~~~
|
||||
# extern crate sync;
|
||||
# use std::sync::Future;
|
||||
fn partial_sum(start: uint) -> f64 {
|
||||
let mut local_sum = 0f64;
|
||||
for num in range(start*100000, (start+1)*100000) {
|
||||
|
|
@ -304,7 +304,7 @@ fn partial_sum(start: uint) -> f64 {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let mut futures = Vec::from_fn(1000, |ind| sync::Future::spawn( proc() { partial_sum(ind) }));
|
||||
let mut futures = Vec::from_fn(1000, |ind| Future::spawn( proc() { partial_sum(ind) }));
|
||||
|
||||
let mut final_res = 0f64;
|
||||
for ft in futures.mut_iter() {
|
||||
|
|
@ -329,10 +329,8 @@ Here is a small example showing how to use Arcs. We wish to run concurrently sev
|
|||
a single large vector of floats. Each task needs the full vector to perform its duty.
|
||||
|
||||
~~~
|
||||
extern crate sync;
|
||||
|
||||
use sync::Arc;
|
||||
use std::rand;
|
||||
use std::sync::Arc;
|
||||
|
||||
fn pnorm(nums: &[f64], p: uint) -> f64 {
|
||||
nums.iter().fold(0.0, |a, b| a + b.powf(p as f64)).powf(1.0 / (p as f64))
|
||||
|
|
@ -357,9 +355,8 @@ at the power given as argument and takes the inverse power of this value). The A
|
|||
created by the line
|
||||
|
||||
~~~
|
||||
# extern crate sync;
|
||||
# use std::rand;
|
||||
# use sync::Arc;
|
||||
# use std::sync::Arc;
|
||||
# fn main() {
|
||||
# let numbers = Vec::from_fn(1000000, |_| rand::random::<f64>());
|
||||
let numbers_arc=Arc::new(numbers);
|
||||
|
|
@ -371,9 +368,8 @@ it's contents. Within the task's procedure, the captured Arc reference can be us
|
|||
reference to the underlying vector as if it were local.
|
||||
|
||||
~~~
|
||||
# extern crate sync;
|
||||
# use std::rand;
|
||||
# use sync::Arc;
|
||||
# use std::sync::Arc;
|
||||
# fn pnorm(nums: &[f64], p: uint) -> f64 { 4.0 }
|
||||
# fn main() {
|
||||
# let numbers=Vec::from_fn(1000000, |_| rand::random::<f64>());
|
||||
|
|
@ -461,9 +457,9 @@ the string in response. The child terminates when it receives `0`.
|
|||
Here is the function that implements the child task:
|
||||
|
||||
~~~
|
||||
extern crate sync;
|
||||
use std::comm::DuplexStream;
|
||||
# fn main() {
|
||||
fn stringifier(channel: &sync::DuplexStream<String, uint>) {
|
||||
fn stringifier(channel: &DuplexStream<String, uint>) {
|
||||
let mut value: uint;
|
||||
loop {
|
||||
value = channel.recv();
|
||||
|
|
@ -485,10 +481,10 @@ response itself is simply the stringified version of the received value,
|
|||
Here is the code for the parent task:
|
||||
|
||||
~~~
|
||||
extern crate sync;
|
||||
use std::comm::duplex;
|
||||
# use std::task::spawn;
|
||||
# use sync::DuplexStream;
|
||||
# fn stringifier(channel: &sync::DuplexStream<String, uint>) {
|
||||
# use std::comm::DuplexStream;
|
||||
# fn stringifier(channel: &DuplexStream<String, uint>) {
|
||||
# let mut value: uint;
|
||||
# loop {
|
||||
# value = channel.recv();
|
||||
|
|
@ -498,7 +494,7 @@ extern crate sync;
|
|||
# }
|
||||
# fn main() {
|
||||
|
||||
let (from_child, to_child) = sync::duplex();
|
||||
let (from_child, to_child) = duplex();
|
||||
|
||||
spawn(proc() {
|
||||
stringifier(&to_child);
|
||||
|
|
|
|||
|
|
@ -297,8 +297,7 @@ an atomically reference counted box ("A.R.C." == "atomically reference counted")
|
|||
Here's some code:
|
||||
|
||||
```
|
||||
extern crate sync;
|
||||
use sync::Arc;
|
||||
use std::sync::Arc;
|
||||
|
||||
fn main() {
|
||||
let numbers = vec![1,2,3];
|
||||
|
|
@ -344,8 +343,7 @@ Let's take the same example yet again,
|
|||
and modify it to mutate the shared state:
|
||||
|
||||
```
|
||||
extern crate sync;
|
||||
use sync::{Arc, Mutex};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
fn main() {
|
||||
let numbers = vec![1,2,3];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue