use std::iter::repeat;
use std::str;
use std::string::String;
-use std::thread::Thread;
+use std::thread;
use std::time::Duration;
use test::MetricMap;
loop {
//waiting 1 second for gdbserver start
timer::sleep(Duration::milliseconds(1000));
- let result = Thread::scoped(move || {
+ let result = thread::spawn(move || {
tcp::TcpStream::connect("127.0.0.1:5039").unwrap();
}).join();
if result.is_err() {
//!
//! ```
//! use std::sync::Arc;
-//! use std::thread::Thread;
+//! use std::thread;
//!
//! let five = Arc::new(5);
//!
//! for _ in 0..10 {
//! let five = five.clone();
//!
-//! Thread::spawn(move || {
+//! thread::spawn(move || {
//! println!("{:?}", five);
//! });
//! }
//!
//! ```
//! use std::sync::{Arc, Mutex};
-//! use std::thread::Thread;
+//! use std::thread;
//!
//! let five = Arc::new(Mutex::new(5));
//!
//! for _ in 0..10 {
//! let five = five.clone();
//!
-//! Thread::spawn(move || {
+//! thread::spawn(move || {
//! let mut number = five.lock().unwrap();
//!
//! *number += 1;
///
/// ```rust
/// use std::sync::Arc;
-/// use std::thread::Thread;
+/// use std::thread;
///
/// fn main() {
/// let numbers: Vec<_> = (0..100u32).map(|i| i as f32).collect();
/// for _ in 0..10 {
/// let child_numbers = shared_numbers.clone();
///
-/// Thread::spawn(move || {
+/// thread::spawn(move || {
/// let local_numbers = child_numbers.as_slice();
///
/// // Work with the local numbers
use std::option::Option::{Some, None};
use std::sync::atomic;
use std::sync::atomic::Ordering::{Acquire, SeqCst};
- use std::thread::Thread;
+ use std::thread;
use std::vec::Vec;
use super::{Arc, Weak, weak_count, strong_count};
use std::sync::Mutex;
let (tx, rx) = channel();
- let _t = Thread::spawn(move || {
+ let _t = thread::spawn(move || {
let arc_v: Arc<Vec<i32>> = rx.recv().unwrap();
assert_eq!((*arc_v)[3], 4);
});
use prelude::*;
use std::rand;
use std::hash::{self, SipHasher};
- use std::thread::Thread;
+ use std::thread;
use test::Bencher;
use test;
#[test]
fn test_send() {
let n = list_from(&[1,2,3]);
- Thread::scoped(move || {
+ thread::spawn(move || {
check_links(&n);
let a: &[_] = &[&1,&2,&3];
assert_eq!(a, n.iter().collect::<Vec<_>>());
//! ```
//! use std::sync::Arc;
//! use std::sync::atomic::{AtomicUsize, Ordering};
-//! use std::thread::Thread;
+//! use std::thread;
//!
//! fn main() {
//! let spinlock = Arc::new(AtomicUsize::new(1));
//!
//! let spinlock_clone = spinlock.clone();
-//! Thread::spawn(move|| {
+//! thread::spawn(move|| {
//! spinlock_clone.store(0, Ordering::SeqCst);
//! });
//!
///
/// ```
/// use std::cell::RefCell;
- /// use std::thread::Thread;
+ /// use std::thread;
///
- /// let result = Thread::scoped(move || {
+ /// let result = thread::spawn(move || {
/// let c = RefCell::new(5);
/// let m = c.borrow_mut();
///
///
/// ```
/// use std::cell::RefCell;
- /// use std::thread::Thread;
+ /// use std::thread;
///
- /// let result = Thread::scoped(move || {
+ /// let result = thread::spawn(move || {
/// let c = RefCell::new(5);
/// let m = c.borrow_mut();
///
#![allow(deprecated)]
use core::finally::{try_finally, Finally};
-use std::thread::Thread;
+use std::thread;
#[test]
fn test_success() {
*i = 10;
},
|i| {
- assert!(!Thread::panicking());
+ assert!(!thread::panicking());
assert_eq!(*i, 10);
*i = 20;
});
panic!();
},
|i| {
- assert!(Thread::panicking());
+ assert!(thread::panicking());
assert_eq!(*i, 10);
})
}
let cr = Path::new(cratefile);
info!("starting to run rustc");
- let (mut krate, analysis) = std::thread::Thread::scoped(move || {
+ let (mut krate, analysis) = std::thread::spawn(move || {
use rustc::session::config::Input;
let cr = cr;
use std::old_io;
use std::env;
use std::str;
-use std::thread::Thread;
+use std::thread;
use std::thunk::Thunk;
use std::collections::{HashSet, HashMap};
let w1 = old_io::ChanWriter::new(tx);
let w2 = w1.clone();
let old = old_io::stdio::set_stderr(box w1);
- Thread::spawn(move || {
+ thread::spawn(move || {
let mut p = old_io::ChanReader::new(rx);
let mut err = match old {
Some(old) => {
/// # Examples
///
/// ```
-/// use std::thread::Thread;
+/// use std::thread;
/// use std::sync::mpsc;
///
/// // two placeholder functions for now
/// let (tx1, rx1) = mpsc::channel();
/// let (tx2, rx2) = mpsc::channel();
///
-/// Thread::spawn(move|| { long_running_task(); tx1.send(()).unwrap(); });
-/// Thread::spawn(move|| { tx2.send(calculate_the_answer()).unwrap(); });
+/// thread::spawn(move|| { long_running_task(); tx1.send(()).unwrap(); });
+/// thread::spawn(move|| { tx2.send(calculate_the_answer()).unwrap(); });
///
/// select! (
/// _ = rx1.recv() => println!("the long running task finished first"),
///
/// ```no_run
/// use std::net::{TcpListener, TcpStream};
-/// use std::thread::Thread;
+/// use std::thread;
///
/// let listener = TcpListener::bind("127.0.0.1:80").unwrap();
///
/// for stream in listener.incoming() {
/// match stream {
/// Ok(stream) => {
-/// Thread::spawn(move|| {
+/// thread::spawn(move|| {
/// // connection succeeded
/// handle_client(stream)
/// });
use net::*;
use net::test::{next_test_ip4, next_test_ip6};
use sync::mpsc::channel;
- use thread::Thread;
+ use thread;
fn each_ip(f: &mut FnMut(SocketAddr)) {
f(next_test_ip4());
let socket_addr = next_test_ip4();
let listener = t!(TcpListener::bind(&socket_addr));
- let _t = Thread::scoped(move || {
+ let _t = thread::spawn(move || {
let mut stream = t!(TcpStream::connect(&("localhost",
socket_addr.port())));
t!(stream.write(&[144]));
let addr = next_test_ip4();
let acceptor = t!(TcpListener::bind(&addr));
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
let mut stream = t!(TcpStream::connect(&("127.0.0.1", addr.port())));
t!(stream.write(&[44]));
});
let addr = next_test_ip6();
let acceptor = t!(TcpListener::bind(&addr));
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
let mut stream = t!(TcpStream::connect(&("::1", addr.port())));
t!(stream.write(&[66]));
});
let acceptor = t!(TcpListener::bind(&addr));
let (tx, rx) = channel();
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
let mut stream = t!(TcpStream::connect(&addr));
t!(stream.write(&[99]));
tx.send(t!(stream.socket_addr())).unwrap();
each_ip(&mut |addr| {
let acceptor = t!(TcpListener::bind(&addr));
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
let _stream = t!(TcpStream::connect(&addr));
// Close
});
let acceptor = t!(TcpListener::bind(&addr));
let (tx, rx) = channel();
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
drop(t!(TcpStream::connect(&addr)));
tx.send(()).unwrap();
});
let max = 10;
let acceptor = t!(TcpListener::bind(&addr));
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
for _ in 0..max {
let mut stream = t!(TcpStream::connect(&addr));
t!(stream.write(&[99]));
each_ip(&mut |addr| {
let acceptor = t!(TcpListener::bind(&addr));
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
let acceptor = acceptor;
for (i, stream) in acceptor.incoming().enumerate().take(MAX) {
// Start another task to handle the connection
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
let mut stream = t!(stream);
let mut buf = [0];
t!(stream.read(&mut buf));
fn connect(i: usize, addr: SocketAddr) {
if i == MAX { return }
- let t = Thread::scoped(move|| {
+ let t = thread::spawn(move|| {
let mut stream = t!(TcpStream::connect(&addr));
// Connect again before writing
connect(i + 1, addr);
each_ip(&mut |addr| {
let acceptor = t!(TcpListener::bind(&addr));
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
for stream in acceptor.incoming().take(MAX) {
// Start another task to handle the connection
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
let mut stream = t!(stream);
let mut buf = [0];
t!(stream.read(&mut buf));
fn connect(i: usize, addr: SocketAddr) {
if i == MAX { return }
- let t = Thread::scoped(move|| {
+ let t = thread::spawn(move|| {
let mut stream = t!(TcpStream::connect(&addr));
connect(i + 1, addr);
t!(stream.write(&[99]));
let listener = t!(TcpListener::bind(&addr));
let so_name = t!(listener.socket_addr());
assert_eq!(addr, so_name);
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
t!(listener.accept());
});
each_ip(&mut |addr| {
let (tx, rx) = channel();
let srv = t!(TcpListener::bind(&addr));
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
let mut cl = t!(srv.accept()).0;
cl.write(&[10]).unwrap();
let mut b = [0];
each_ip(&mut |addr| {
let acceptor = t!(TcpListener::bind(&addr));
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
t!(TcpStream::connect(&addr));
});
each_ip(&mut |addr| {
let acceptor = t!(TcpListener::bind(&addr));
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
let mut s = t!(TcpStream::connect(&addr));
let mut buf = [0, 0];
assert_eq!(s.read(&mut buf), Ok(1));
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
let mut s2 = s2;
rx1.recv().unwrap();
t!(s2.write(&[1]));
let (tx1, rx) = channel();
let tx2 = tx1.clone();
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
let mut s = t!(TcpStream::connect(&addr));
t!(s.write(&[1]));
rx.recv().unwrap();
let s2 = t!(s1.try_clone());
let (done, rx) = channel();
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
let mut s2 = s2;
let mut buf = [0, 0];
t!(s2.read(&mut buf));
each_ip(&mut |addr| {
let acceptor = t!(TcpListener::bind(&addr));
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
let mut s = t!(TcpStream::connect(&addr));
let mut buf = [0, 1];
t!(s.read(&mut buf));
let s2 = t!(s1.try_clone());
let (done, rx) = channel();
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
let mut s2 = s2;
t!(s2.write(&[1]));
done.send(()).unwrap();
fn shutdown_smoke() {
each_ip(&mut |addr| {
let a = t!(TcpListener::bind(&addr));
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
let mut c = t!(a.accept()).0;
let mut b = [0];
assert_eq!(c.read(&mut b), Ok(0));
each_ip(&mut |addr| {
let a = t!(TcpListener::bind(&addr));
let (tx, rx) = channel::<()>();
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
let _s = t!(a.accept());
let _ = rx.recv();
});
each_ip(&mut |addr| {
let a = t!(TcpListener::bind(&addr));
let (tx1, rx) = channel::<()>();
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
let _s = t!(a.accept());
let _ = rx.recv();
});
let s = t!(TcpStream::connect(&addr));
let s2 = t!(s.try_clone());
let (tx, rx) = channel();
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
let mut s2 = s2;
assert_eq!(t!(s2.read(&mut [0])), 0);
tx.send(()).unwrap();
let (tx, rx) = channel();
let (txdone, rxdone) = channel();
let txdone2 = txdone.clone();
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
let mut tcp = t!(TcpStream::connect(&addr));
rx.recv().unwrap();
t!(tcp.write(&[0]));
let tcp = t!(accept.accept()).0;
let tcp2 = t!(tcp.try_clone());
let txdone3 = txdone.clone();
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
let mut tcp2 = tcp2;
t!(tcp2.read(&mut [0]));
txdone3.send(()).unwrap();
// Try to ensure that the reading clone is indeed reading
for _ in 0..50 {
- Thread::yield_now();
+ thread::yield_now();
}
// clone the handle again while it's reading, then let it finish the
let a = t!(TcpListener::bind(&addr));
let a2 = t!(a.try_clone());
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
let _ = TcpStream::connect(&addr);
});
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
let _ = TcpStream::connect(&addr);
});
let (tx, rx) = channel();
let tx2 = tx.clone();
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
tx.send(t!(a.accept())).unwrap();
});
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
tx2.send(t!(a2.accept())).unwrap();
});
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
let _ = TcpStream::connect(&addr);
});
- let _t = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
let _ = TcpStream::connect(&addr);
});
use net::*;
use net::test::{next_test_ip4, next_test_ip6};
use sync::mpsc::channel;
- use thread::Thread;
+ use thread;
fn each_ip(f: &mut FnMut(SocketAddr, SocketAddr)) {
f(next_test_ip4(), next_test_ip4());
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let client = t!(UdpSocket::bind(&client_ip));
rx1.recv().unwrap();
t!(client.send_to(&[99], &server_ip));
let sock1 = t!(UdpSocket::bind(&addr1));
let sock2 = t!(UdpSocket::bind(&addr2));
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut buf = [0, 0];
assert_eq!(sock2.recv_from(&mut buf), Ok((1, addr1)));
assert_eq!(buf[0], 1);
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
rx1.recv().unwrap();
t!(sock3.send_to(&[1], &addr2));
tx2.send(()).unwrap();
let (tx1, rx) = channel();
let tx2 = tx1.clone();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
t!(sock2.send_to(&[1], &addr1));
rx.recv().unwrap();
t!(sock2.send_to(&[2], &addr1));
let sock3 = t!(sock1.try_clone());
let (done, rx) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut buf = [0, 0];
t!(sock3.recv_from(&mut buf));
tx2.send(()).unwrap();
let (tx, rx) = channel();
let (serv_tx, serv_rx) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut buf = [0, 1];
rx.recv().unwrap();
t!(sock2.recv_from(&mut buf));
let (done, rx) = channel();
let tx2 = tx.clone();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
match sock3.send_to(&[1], &addr2) {
Ok(..) => { let _ = tx2.send(()); }
Err(..) => {}
use sync::mpsc::channel;
use super::*;
use old_io;
- use thread::Thread;
+ use thread;
#[test]
fn test_rx_reader() {
let (tx, rx) = channel();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
tx.send(vec![1u8, 2u8]).unwrap();
tx.send(vec![]).unwrap();
tx.send(vec![3u8, 4u8]).unwrap();
#[test]
fn test_rx_buffer() {
let (tx, rx) = channel();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
tx.send(b"he".to_vec()).unwrap();
tx.send(b"llo wo".to_vec()).unwrap();
tx.send(b"".to_vec()).unwrap();
writer.write_be_u32(42).unwrap();
let wanted = vec![0u8, 0u8, 0u8, 42u8];
- let got = match Thread::scoped(move|| { rx.recv().unwrap() }).join() {
+ let got = match thread::spawn(move|| { rx.recv().unwrap() }).join() {
Ok(got) => got,
Err(_) => panic!(),
};
//! # #![allow(dead_code)]
//! use std::old_io::{TcpListener, TcpStream};
//! use std::old_io::{Acceptor, Listener};
-//! use std::thread::Thread;
+//! use std::thread;
//!
//! let listener = TcpListener::bind("127.0.0.1:80");
//!
//! match stream {
//! Err(e) => { /* connection failed */ }
//! Ok(stream) => {
-//! Thread::spawn(move|| {
+//! thread::spawn(move|| {
//! // connection succeeded
//! handle_client(stream)
//! });
use old_io::test::*;
use super::*;
use sync::mpsc::channel;
- use thread::Thread;
+ use thread;
use time::Duration;
pub fn smalltest<F,G>(server: F, client: G)
let mut acceptor = UnixListener::bind(&path1).listen();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
match UnixStream::connect(&path2) {
Ok(c) => client(c),
Err(e) => panic!("failed connect: {}", e),
Err(e) => panic!("failed listen: {}", e),
};
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
for _ in 0u..times {
let mut stream = UnixStream::connect(&path2);
match stream.write(&[100]) {
let addr = next_test_unix();
let mut acceptor = UnixListener::bind(&addr).listen();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut s = UnixStream::connect(&addr);
let mut buf = [0, 0];
debug!("client reading");
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut s2 = s2;
rx1.recv().unwrap();
debug!("writer writing");
let (tx1, rx) = channel();
let tx2 = tx1.clone();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut s = UnixStream::connect(&addr);
s.write(&[1]).unwrap();
rx.recv().unwrap();
let s2 = s1.clone();
let (done, rx) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut s2 = s2;
let mut buf = [0, 0];
s2.read(&mut buf).unwrap();
let addr = next_test_unix();
let mut acceptor = UnixListener::bind(&addr).listen();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut s = UnixStream::connect(&addr);
let buf = &mut [0, 1];
s.read(buf).unwrap();
let s2 = s1.clone();
let (tx, rx) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut s2 = s2;
s2.write(&[1]).unwrap();
tx.send(()).unwrap();
// continue to receive any pending connections.
let (tx, rx) = channel();
let addr2 = addr.clone();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
tx.send(UnixStream::connect(&addr2).unwrap()).unwrap();
});
let l = rx.recv().unwrap();
Err(ref e) if e.kind == TimedOut => {}
Err(e) => panic!("error: {}", e),
}
- ::thread::Thread::yield_now();
+ ::thread::yield_now();
if i == 1000 { panic!("should have a pending connection") }
}
drop(l);
// Unset the timeout and make sure that this always blocks.
a.set_timeout(None);
let addr2 = addr.clone();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
drop(UnixStream::connect(&addr2).unwrap());
});
a.accept().unwrap();
let addr = next_test_unix();
let a = UnixListener::bind(&addr).listen().unwrap();
let (_tx, rx) = channel::<()>();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
let mut a = a;
let _s = a.accept().unwrap();
let _ = rx.recv();
let addr = next_test_unix();
let a = UnixListener::bind(&addr).listen().unwrap();
let (_tx, rx) = channel::<()>();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
let mut a = a;
let _s = a.accept().unwrap();
let _ = rx.recv();
let mut s = UnixStream::connect(&addr).unwrap();
let s2 = s.clone();
let (tx, rx) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut s2 = s2;
assert!(s2.read(&mut [0]).is_err());
tx.send(()).unwrap();
let addr = next_test_unix();
let mut a = UnixListener::bind(&addr).listen().unwrap();
let (tx, rx) = channel::<()>();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
let mut s = UnixStream::connect(&addr).unwrap();
rx.recv().unwrap();
assert!(s.write(&[0]).is_ok());
let addr = next_test_unix();
let mut a = UnixListener::bind(&addr).listen().unwrap();
let (tx, rx) = channel::<()>();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
let mut s = UnixStream::connect(&addr).unwrap();
rx.recv().unwrap();
let mut amt = 0;
let addr = next_test_unix();
let mut a = UnixListener::bind(&addr).listen().unwrap();
let (tx, rx) = channel::<()>();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
let mut s = UnixStream::connect(&addr).unwrap();
rx.recv().unwrap();
assert!(s.write(&[0]).is_ok());
let addr = next_test_unix();
let mut a = UnixListener::bind(&addr).listen().unwrap();
let (tx, rx) = channel::<()>();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
let mut s = UnixStream::connect(&addr).unwrap();
rx.recv().unwrap();
assert!(s.write(&[0]).is_ok());
let mut s = a.accept().unwrap();
let s2 = s.clone();
let (tx2, rx2) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut s2 = s2;
assert!(s2.read(&mut [0]).is_ok());
tx2.send(()).unwrap();
let mut a2 = a.clone();
let addr2 = addr.clone();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let _ = UnixStream::connect(&addr2);
});
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let _ = UnixStream::connect(&addr);
});
let (tx, rx) = channel();
let tx2 = tx.clone();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut a = a;
tx.send(a.accept()).unwrap()
});
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut a = a2;
tx2.send(a.accept()).unwrap()
});
let addr2 = addr.clone();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let _ = UnixStream::connect(&addr2);
});
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let _ = UnixStream::connect(&addr);
});
let mut a2 = a.clone();
let (tx, rx) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut a = a;
tx.send(a.accept()).unwrap();
});
/// use std::old_io::timer;
/// use std::old_io::TcpStream;
/// use std::time::Duration;
- /// use std::thread::Thread;
+ /// use std::thread;
///
/// let mut stream = TcpStream::connect("127.0.0.1:34254").unwrap();
/// let stream2 = stream.clone();
///
- /// let _t = Thread::spawn(move|| {
+ /// let _t = thread::spawn(move|| {
/// // close this stream after one second
/// timer::sleep(Duration::seconds(1));
/// let mut stream = stream2;
/// # fn foo() {
/// use std::old_io::{TcpListener, TcpStream};
/// use std::old_io::{Acceptor, Listener};
-/// use std::thread::Thread;
+/// use std::thread;
///
/// let listener = TcpListener::bind("127.0.0.1:80").unwrap();
///
/// match stream {
/// Err(e) => { /* connection failed */ }
/// Ok(stream) => {
-/// Thread::spawn(move|| {
+/// thread::spawn(move|| {
/// // connection succeeded
/// handle_client(stream)
/// });
///
/// ```
/// use std::old_io::{TcpListener, Listener, Acceptor, EndOfFile};
- /// use std::thread::Thread;
+ /// use std::thread;
///
/// let mut a = TcpListener::bind("127.0.0.1:8482").listen().unwrap();
/// let a2 = a.clone();
///
- /// let _t = Thread::spawn(move|| {
+ /// let _t = thread::spawn(move|| {
/// let mut a2 = a2;
/// for socket in a2.incoming() {
/// match socket {
use prelude::v1::*;
use sync::mpsc::channel;
- use thread::Thread;
+ use thread;
use old_io::net::tcp::*;
use old_io::net::ip::*;
use old_io::test::*;
let listener = TcpListener::bind(socket_addr);
let mut acceptor = listener.listen();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut stream = TcpStream::connect(("localhost", socket_addr.port));
stream.write(&[144]).unwrap();
});
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut stream = TcpStream::connect(("localhost", addr.port));
stream.write(&[64]).unwrap();
});
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut stream = TcpStream::connect(("127.0.0.1", addr.port));
stream.write(&[44]).unwrap();
});
let addr = next_test_ip6();
let mut acceptor = TcpListener::bind(addr).listen();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut stream = TcpStream::connect(("::1", addr.port));
stream.write(&[66]).unwrap();
});
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut stream = TcpStream::connect(addr);
stream.write(&[99]).unwrap();
});
let addr = next_test_ip6();
let mut acceptor = TcpListener::bind(addr).listen();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut stream = TcpStream::connect(addr);
stream.write(&[99]).unwrap();
});
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let _stream = TcpStream::connect(addr);
// Close
});
let addr = next_test_ip6();
let mut acceptor = TcpListener::bind(addr).listen();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let _stream = TcpStream::connect(addr);
// Close
});
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let _stream = TcpStream::connect(addr);
// Close
});
let addr = next_test_ip6();
let mut acceptor = TcpListener::bind(addr).listen();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let _stream = TcpStream::connect(addr);
// Close
});
let mut acceptor = TcpListener::bind(addr).listen();
let (tx, rx) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
drop(TcpStream::connect(addr));
tx.send(()).unwrap();
});
let mut acceptor = TcpListener::bind(addr).listen();
let (tx, rx) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
drop(TcpStream::connect(addr));
tx.send(()).unwrap();
});
let max = 10u;
let mut acceptor = TcpListener::bind(addr).listen();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
for _ in 0..max {
let mut stream = TcpStream::connect(addr);
stream.write(&[99]).unwrap();
let max = 10u;
let mut acceptor = TcpListener::bind(addr).listen();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
for _ in 0..max {
let mut stream = TcpStream::connect(addr);
stream.write(&[99]).unwrap();
static MAX: int = 10;
let acceptor = TcpListener::bind(addr).listen();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut acceptor = acceptor;
for (i, stream) in acceptor.incoming().enumerate().take(MAX as uint) {
// Start another task to handle the connection
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut stream = stream;
let mut buf = [0];
stream.read(&mut buf).unwrap();
fn connect(i: int, addr: SocketAddr) {
if i == MAX { return }
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
debug!("connecting");
let mut stream = TcpStream::connect(addr);
// Connect again before writing
static MAX: int = 10;
let acceptor = TcpListener::bind(addr).listen();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut acceptor = acceptor;
for (i, stream) in acceptor.incoming().enumerate().take(MAX as uint) {
// Start another task to handle the connection
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut stream = stream;
let mut buf = [0];
stream.read(&mut buf).unwrap();
fn connect(i: int, addr: SocketAddr) {
if i == MAX { return }
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
debug!("connecting");
let mut stream = TcpStream::connect(addr);
// Connect again before writing
let addr = next_test_ip4();
let acceptor = TcpListener::bind(addr).listen();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut acceptor = acceptor;
for stream in acceptor.incoming().take(MAX as uint) {
// Start another task to handle the connection
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut stream = stream;
let mut buf = [0];
stream.read(&mut buf).unwrap();
fn connect(i: int, addr: SocketAddr) {
if i == MAX { return }
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
debug!("connecting");
let mut stream = TcpStream::connect(addr);
// Connect again before writing
let addr = next_test_ip6();
let acceptor = TcpListener::bind(addr).listen();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut acceptor = acceptor;
for stream in acceptor.incoming().take(MAX as uint) {
// Start another task to handle the connection
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut stream = stream;
let mut buf = [0];
stream.read(&mut buf).unwrap();
fn connect(i: int, addr: SocketAddr) {
if i == MAX { return }
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
debug!("connecting");
let mut stream = TcpStream::connect(addr);
// Connect again before writing
pub fn peer_name(addr: SocketAddr) {
let acceptor = TcpListener::bind(addr).listen();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut acceptor = acceptor;
acceptor.accept().unwrap();
});
fn partial_read() {
let addr = next_test_ip4();
let (tx, rx) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut srv = TcpListener::bind(addr).listen().unwrap();
tx.send(()).unwrap();
let mut cl = srv.accept().unwrap();
let addr = next_test_ip4();
let (tx, rx) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
rx.recv().unwrap();
let _stream = TcpStream::connect(addr).unwrap();
// Close
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut s = TcpStream::connect(addr);
let mut buf = [0, 0];
assert_eq!(s.read(&mut buf), Ok(1));
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut s2 = s2;
rx1.recv().unwrap();
s2.write(&[1]).unwrap();
let (tx1, rx) = channel();
let tx2 = tx1.clone();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut s = TcpStream::connect(addr);
s.write(&[1]).unwrap();
rx.recv().unwrap();
let s2 = s1.clone();
let (done, rx) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut s2 = s2;
let mut buf = [0, 0];
s2.read(&mut buf).unwrap();
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut s = TcpStream::connect(addr);
let mut buf = [0, 1];
s.read(&mut buf).unwrap();
let s2 = s1.clone();
let (done, rx) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut s2 = s2;
s2.write(&[1]).unwrap();
done.send(()).unwrap();
fn shutdown_smoke() {
let addr = next_test_ip4();
let a = TcpListener::bind(addr).unwrap().listen();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut a = a;
let mut c = a.accept().unwrap();
assert_eq!(c.read_to_end(), Ok(vec!()));
// flakiness.
if !cfg!(target_os = "freebsd") {
let (tx, rx) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
tx.send(TcpStream::connect(addr).unwrap()).unwrap();
});
let _l = rx.recv().unwrap();
Err(ref e) if e.kind == TimedOut => {}
Err(e) => panic!("error: {}", e),
}
- ::thread::Thread::yield_now();
+ ::thread::yield_now();
if i == 1000 { panic!("should have a pending connection") }
}
}
// Unset the timeout and make sure that this always blocks.
a.set_timeout(None);
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
drop(TcpStream::connect(addr).unwrap());
});
a.accept().unwrap();
let addr = next_test_ip4();
let a = TcpListener::bind(addr).listen().unwrap();
let (_tx, rx) = channel::<()>();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
let mut a = a;
let _s = a.accept().unwrap();
let _ = rx.recv().unwrap();
let addr = next_test_ip4();
let a = TcpListener::bind(addr).listen().unwrap();
let (_tx, rx) = channel::<()>();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
let mut a = a;
let _s = a.accept().unwrap();
let _ = rx.recv().unwrap();
let mut s = TcpStream::connect(addr).unwrap();
let s2 = s.clone();
let (tx, rx) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut s2 = s2;
assert!(s2.read(&mut [0]).is_err());
tx.send(()).unwrap();
let addr = next_test_ip6();
let mut a = TcpListener::bind(addr).listen().unwrap();
let (tx, rx) = channel::<()>();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
let mut s = TcpStream::connect(addr).unwrap();
rx.recv().unwrap();
assert!(s.write(&[0]).is_ok());
let addr = next_test_ip6();
let mut a = TcpListener::bind(addr).listen().unwrap();
let (tx, rx) = channel::<()>();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
let mut s = TcpStream::connect(addr).unwrap();
rx.recv().unwrap();
let mut amt = 0;
let addr = next_test_ip6();
let mut a = TcpListener::bind(addr).listen().unwrap();
let (tx, rx) = channel::<()>();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
let mut s = TcpStream::connect(addr).unwrap();
rx.recv().unwrap();
assert!(s.write(&[0]).is_ok());
let addr = next_test_ip6();
let mut a = TcpListener::bind(addr).listen().unwrap();
let (tx, rx) = channel::<()>();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
let mut s = TcpStream::connect(addr).unwrap();
rx.recv().unwrap();
assert_eq!(s.write(&[0]), Ok(()));
let mut s = a.accept().unwrap();
let s2 = s.clone();
let (tx2, rx2) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut s2 = s2;
assert_eq!(s2.read(&mut [0]), Ok(1));
tx2.send(()).unwrap();
let (tx, rx) = channel();
let (txdone, rxdone) = channel();
let txdone2 = txdone.clone();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut tcp = TcpStream::connect(addr).unwrap();
rx.recv().unwrap();
tcp.write_u8(0).unwrap();
let tcp = accept.accept().unwrap();
let tcp2 = tcp.clone();
let txdone3 = txdone.clone();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut tcp2 = tcp2;
tcp2.read_u8().unwrap();
txdone3.send(()).unwrap();
// Try to ensure that the reading clone is indeed reading
for _ in 0..50 {
- ::thread::Thread::yield_now();
+ ::thread::yield_now();
}
// clone the handle again while it's reading, then let it finish the
let mut a = l.listen().unwrap();
let mut a2 = a.clone();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let _ = TcpStream::connect(addr);
});
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let _ = TcpStream::connect(addr);
});
let (tx, rx) = channel();
let tx2 = tx.clone();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut a = a;
tx.send(a.accept()).unwrap();
});
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut a = a2;
tx2.send(a.accept()).unwrap();
});
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let _ = TcpStream::connect(addr);
});
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let _ = TcpStream::connect(addr);
});
let mut a2 = a.clone();
let (tx, rx) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut a = a;
tx.send(a.accept()).unwrap();
});
use old_io::test::*;
use old_io::{IoError, TimedOut, PermissionDenied, ShortWrite};
use super::*;
- use thread::Thread;
+ use thread;
// FIXME #11530 this fails on android because tests are run as root
#[cfg_attr(any(windows, target_os = "android"), ignore)]
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
match UdpSocket::bind(client_ip) {
Ok(ref mut client) => {
rx1.recv().unwrap();
let client_ip = next_test_ip6();
let (tx, rx) = channel::<()>();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
match UdpSocket::bind(client_ip) {
Ok(ref mut client) => {
rx.recv().unwrap();
let mut sock1 = UdpSocket::bind(addr1).unwrap();
let sock2 = UdpSocket::bind(addr2).unwrap();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut sock2 = sock2;
let mut buf = [0, 0];
assert_eq!(sock2.recv_from(&mut buf), Ok((1, addr1)));
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut sock3 = sock3;
rx1.recv().unwrap();
sock3.send_to(&[1], addr2).unwrap();
let (tx1, rx) = channel();
let tx2 = tx1.clone();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut sock2 = sock2;
sock2.send_to(&[1], addr1).unwrap();
rx.recv().unwrap();
let sock3 = sock1.clone();
let (done, rx) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut sock3 = sock3;
let mut buf = [0, 0];
sock3.recv_from(&mut buf).unwrap();
let (tx, rx) = channel();
let (serv_tx, serv_rx) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut sock2 = sock2;
let mut buf = [0, 1];
let (done, rx) = channel();
let tx2 = tx.clone();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut sock3 = sock3;
match sock3.send_to(&[1], addr2) {
Ok(..) => { let _ = tx2.send(()); }
let (tx, rx) = channel();
let (tx2, rx2) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut a = a2;
assert_eq!(a.recv_from(&mut [0]), Ok((1, addr1)));
assert_eq!(a.send_to(&[0], addr1), Ok(()));
use prelude::v1::*;
use sync::mpsc::channel;
- use thread::Thread;
+ use thread;
#[test]
fn partial_read() {
let out = PipeStream::open(writer);
let mut input = PipeStream::open(reader);
let (tx, rx) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut out = out;
out.write(&[10]).unwrap();
rx.recv().unwrap(); // don't close the pipe until the other read has finished
use sys::fs::FileDesc;
use sys::process::Process as ProcessImp;
use sys;
-use thread::Thread;
+use thread;
#[cfg(windows)] use hash;
#[cfg(windows)] use str;
let (tx, rx) = channel();
match stream {
Some(stream) => {
- Thread::spawn(move || {
+ thread::spawn(move || {
let mut stream = stream;
tx.send(stream.read_to_end()).unwrap();
});
use super::{CreatePipe};
use super::{InheritFd, Process, PleaseExitSignal, Command, ProcessOutput};
use sync::mpsc::channel;
- use thread::Thread;
+ use thread;
use time::Duration;
// FIXME(#10380) these tests should not all be ignored on android.
fn wait_timeout2() {
let (tx, rx) = channel();
let tx2 = tx.clone();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut p = sleeper();
p.set_timeout(Some(10));
assert_eq!(p.wait().err().unwrap().kind, TimedOut);
p.signal_kill().unwrap();
tx.send(()).unwrap();
});
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut p = sleeper();
p.set_timeout(Some(10));
assert_eq!(p.wait().err().unwrap().kind, TimedOut);
use super::*;
use sync::mpsc::channel;
- use thread::Thread;
+ use thread;
#[test]
fn smoke() {
let (tx, rx) = channel();
let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx));
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
set_stdout(box w);
println!("hello!");
});
let (tx, rx) = channel();
let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx));
- let _t = Thread::spawn(move || -> () {
+ let _t = thread::spawn(move || -> () {
set_stderr(box w);
panic!("my special message");
});
#[cfg(test)]
mod test {
use super::Timer;
- use thread::Thread;
+ use thread;
use time::Duration;
#[test]
fn test_timer_send() {
let mut timer = Timer::new().unwrap();
- Thread::spawn(move || timer.sleep(Duration::milliseconds(1)));
+ thread::spawn(move || timer.sleep(Duration::milliseconds(1)));
}
#[test]
let mut timer = Timer::new().unwrap();
let timer_rx = timer.periodic(Duration::milliseconds(1000));
- Thread::spawn(move|| {
+ thread::spawn(move|| {
let _ = timer_rx.recv();
});
let mut timer = Timer::new().unwrap();
let timer_rx = timer.periodic(Duration::milliseconds(1000));
- Thread::spawn(move|| {
+ thread::spawn(move|| {
let _ = timer_rx.recv();
});
let mut timer = Timer::new().unwrap();
let timer_rx = timer.periodic(Duration::milliseconds(1000));
- Thread::spawn(move|| {
+ thread::spawn(move|| {
let _ = timer_rx.recv();
});
#[test]
fn test_null_byte() {
- use thread::Thread;
- let result = Thread::scoped(move|| {
+ use thread;
+ let result = thread::spawn(move|| {
Path::new(b"foo/bar\0")
}).join();
assert!(result.is_err());
- let result = Thread::scoped(move|| {
+ let result = thread::spawn(move|| {
Path::new("test").set_filename(b"f\0o")
}).join();
assert!(result.is_err());
- let result = Thread::scoped(move|| {
+ let result = thread::spawn(move|| {
Path::new("test").push(b"f\0o");
}).join();
assert!(result.is_err());
#[test]
fn test_null_byte() {
- use thread::Thread;
- let result = Thread::scoped(move|| {
+ use thread;
+ let result = thread::spawn(move|| {
Path::new(b"foo/bar\0")
}).join();
assert!(result.is_err());
- let result = Thread::scoped(move|| {
+ let result = thread::spawn(move|| {
Path::new("test").set_filename(b"f\0o")
}).join();
assert!(result.is_err());
- let result = Thread::scoped(move || {
+ let result = thread::spawn(move || {
Path::new("test").push(b"f\0o");
}).join();
assert!(result.is_err());
use old_io::IoResult;
use rt::{backtrace, unwind};
use rt::util::{Stderr, Stdio};
-use thread::Thread;
+use thread;
// Defined in this module instead of old_io::stdio so that the unwinding
thread_local! {
}
};
let mut err = Stderr;
- let thread = Thread::current();
+ let thread = thread::current();
let name = thread.name().unwrap_or("<unnamed>");
let prev = LOCAL_STDERR.with(|s| s.borrow_mut().take());
match prev {
use sys::process2::Command as CommandImp;
use sys::process2::ExitStatus as ExitStatusImp;
use sys_common::{AsInner, AsInnerMut};
-use thread::Thread;
+use thread;
/// Representation of a running or exited child process.
///
let (tx, rx) = channel();
match stream {
Some(stream) => {
- Thread::spawn(move || {
+ thread::spawn(move || {
let mut stream = stream;
let mut ret = Vec::new();
let res = stream.read_to_end(&mut ret);
use str;
use super::{Child, Command, Output, ExitStatus, Stdio};
use sync::mpsc::channel;
- use thread::Thread;
+ use thread;
use time::Duration;
// FIXME(#10380) these tests should not all be ignored on android.
use sync::mpsc::channel;
use rand::Rng;
use super::OsRng;
- use thread::Thread;
+ use thread;
#[test]
fn test_os_rng() {
let (tx, rx) = channel();
txs.push(tx);
- Thread::spawn(move|| {
+ thread::spawn(move|| {
// wait until all the tasks are ready to go.
rx.recv().unwrap();
// deschedule to attempt to interleave things as much
// as possible (XXX: is this a good test?)
let mut r = OsRng::new().unwrap();
- Thread::yield_now();
+ thread::yield_now();
let mut v = [0u8; 1000];
for _ in 0u..100 {
r.next_u32();
- Thread::yield_now();
+ thread::yield_now();
r.next_u64();
- Thread::yield_now();
+ thread::yield_now();
r.fill_bytes(&mut v);
- Thread::yield_now();
+ thread::yield_now();
}
});
}
}
pub unsafe fn report_overflow() {
- use thread::Thread;
+ use thread;
// See the message below for why this is not emitted to the
// ^ Where did the message below go?
// and the FFI call needs 2MB of stack when we just ran out.
rterrln!("\nthread '{}' has overflowed its stack",
- Thread::current().name().unwrap_or("<unknown>"));
+ thread::current().name().unwrap_or("<unknown>"));
}
///
/// ```rust
/// use std::sync::{Arc, Barrier};
-/// use std::thread::Thread;
+/// use std::thread;
///
/// let barrier = Arc::new(Barrier::new(10));
/// for _ in 0u..10 {
/// let c = barrier.clone();
/// // The same messages will be printed together.
/// // You will NOT see any interleaving.
-/// Thread::spawn(move|| {
+/// thread::spawn(move|| {
/// println!("before wait");
/// c.wait();
/// println!("after wait");
use sync::{Arc, Barrier};
use sync::mpsc::{channel, TryRecvError};
- use thread::Thread;
+ use thread;
#[test]
fn test_barrier() {
for _ in 0u..N - 1 {
let c = barrier.clone();
let tx = tx.clone();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
tx.send(c.wait().is_leader()).unwrap();
});
}
///
/// ```
/// use std::sync::{Arc, Mutex, Condvar};
-/// use std::thread::Thread;
+/// use std::thread;
///
/// let pair = Arc::new((Mutex::new(false), Condvar::new()));
/// let pair2 = pair.clone();
///
/// // Inside of our lock, spawn a new thread, and then wait for it to start
-/// Thread::spawn(move|| {
+/// thread::spawn(move|| {
/// let &(ref lock, ref cvar) = &*pair2;
/// let mut started = lock.lock().unwrap();
/// *started = true;
use sync::mpsc::channel;
use sync::{StaticMutex, MUTEX_INIT, Condvar, Mutex, Arc};
use sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
- use thread::Thread;
+ use thread;
use time::Duration;
#[test]
static M: StaticMutex = MUTEX_INIT;
let g = M.lock().unwrap();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let _g = M.lock().unwrap();
C.notify_one();
});
for _ in 0..N {
let data = data.clone();
let tx = tx.clone();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
let &(ref lock, ref cond) = &*data;
let mut cnt = lock.lock().unwrap();
*cnt += 1;
let (g, _no_timeout) = C.wait_timeout(g, Duration::nanoseconds(1000)).unwrap();
// spurious wakeups mean this isn't necessarily true
// assert!(!no_timeout);
- let _t = Thread::spawn(move || {
+ let _t = thread::spawn(move || {
let _g = M.lock().unwrap();
C.notify_one();
});
assert!(!success);
let (tx, rx) = channel();
- let _t = Thread::scoped(move || {
+ let _t = thread::spawn(move || {
rx.recv().unwrap();
let g = M.lock().unwrap();
S.store(1, Ordering::SeqCst);
static C: StaticCondvar = CONDVAR_INIT;
let mut g = M1.lock().unwrap();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let _g = M1.lock().unwrap();
C.notify_one();
});
use self::FutureState::*;
use sync::mpsc::{Receiver, channel};
use thunk::{Thunk};
-use thread::Thread;
+use thread;
/// A type encapsulating the result of a computation which may not be complete
pub struct Future<A> {
let (tx, rx) = channel();
- Thread::spawn(move || {
+ thread::spawn(move || {
// Don't panic if the other end has hung up
let _ = tx.send(blk());
});
use prelude::v1::*;
use sync::mpsc::channel;
use sync::Future;
- use thread::Thread;
+ use thread;
#[test]
fn test_from_value() {
let expected = "schlorf";
let (tx, rx) = channel();
let f = Future::spawn(move|| { expected });
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut f = f;
tx.send(f.get()).unwrap();
});
//! Generic support for building blocking abstractions.
-use thread::Thread;
+use thread::{self, Thread};
use sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering};
use sync::Arc;
use marker::{Sync, Send};
pub fn tokens() -> (WaitToken, SignalToken) {
let inner = Arc::new(Inner {
- thread: Thread::current(),
+ thread: thread::current(),
woken: ATOMIC_BOOL_INIT,
});
let wait_token = WaitToken {
impl WaitToken {
pub fn wait(self) {
while !self.inner.woken.load(Ordering::SeqCst) {
- Thread::park()
+ thread::park()
}
}
}
//! Simple usage:
//!
//! ```
-//! use std::thread::Thread;
+//! use std::thread;
//! use std::sync::mpsc::channel;
//!
//! // Create a simple streaming channel
//! let (tx, rx) = channel();
-//! Thread::spawn(move|| {
+//! thread::spawn(move|| {
//! tx.send(10).unwrap();
//! });
//! assert_eq!(rx.recv().unwrap(), 10);
//! Shared usage:
//!
//! ```
-//! use std::thread::Thread;
+//! use std::thread;
//! use std::sync::mpsc::channel;
//!
//! // Create a shared channel that can be sent along from many threads
//! let (tx, rx) = channel();
//! for i in 0..10 {
//! let tx = tx.clone();
-//! Thread::spawn(move|| {
+//! thread::spawn(move|| {
//! tx.send(i).unwrap();
//! });
//! }
//! Synchronous channels:
//!
//! ```
-//! use std::thread::Thread;
+//! use std::thread;
//! use std::sync::mpsc::sync_channel;
//!
//! let (tx, rx) = sync_channel::<int>(0);
-//! Thread::spawn(move|| {
+//! thread::spawn(move|| {
//! // This will wait for the parent task to start receiving
//! tx.send(53).unwrap();
//! });
///
/// ```
/// use std::sync::mpsc::channel;
-/// use std::thread::Thread;
+/// use std::thread;
///
/// // tx is is the sending half (tx for transmission), and rx is the receiving
/// // half (rx for receiving).
/// let (tx, rx) = channel();
///
/// // Spawn off an expensive computation
-/// Thread::spawn(move|| {
+/// thread::spawn(move|| {
/// # fn expensive_computation() {}
/// tx.send(expensive_computation()).unwrap();
/// });
///
/// ```
/// use std::sync::mpsc::sync_channel;
-/// use std::thread::Thread;
+/// use std::thread;
///
/// let (tx, rx) = sync_channel(1);
///
/// // this returns immediately
/// tx.send(1).unwrap();
///
-/// Thread::spawn(move|| {
+/// thread::spawn(move|| {
/// // this will block until the previous message has been received
/// tx.send(2).unwrap();
/// });
use std::env;
use super::*;
- use thread::Thread;
+ use thread;
pub fn stress_factor() -> uint {
match env::var("RUST_TEST_STRESS") {
#[test]
fn smoke_threads() {
let (tx, rx) = channel::<int>();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
tx.send(1).unwrap();
});
assert_eq!(rx.recv().unwrap(), 1);
#[test]
fn port_gone_concurrent() {
let (tx, rx) = channel::<int>();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
rx.recv().unwrap();
});
while tx.send(1).is_ok() {}
fn port_gone_concurrent_shared() {
let (tx, rx) = channel::<int>();
let tx2 = tx.clone();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
rx.recv().unwrap();
});
while tx.send(1).is_ok() && tx2.send(1).is_ok() {}
#[test]
fn chan_gone_concurrent() {
let (tx, rx) = channel::<int>();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
tx.send(1).unwrap();
tx.send(1).unwrap();
});
#[test]
fn stress() {
let (tx, rx) = channel::<int>();
- let t = Thread::scoped(move|| {
+ let t = thread::spawn(move|| {
for _ in 0u..10000 { tx.send(1).unwrap(); }
});
for _ in 0u..10000 {
static NTHREADS: uint = 8;
let (tx, rx) = channel::<int>();
- let t = Thread::scoped(move|| {
+ let t = thread::spawn(move|| {
for _ in 0..AMT * NTHREADS {
assert_eq!(rx.recv().unwrap(), 1);
}
for _ in 0..NTHREADS {
let tx = tx.clone();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
for _ in 0..AMT { tx.send(1).unwrap(); }
});
}
fn send_from_outside_runtime() {
let (tx1, rx1) = channel::<()>();
let (tx2, rx2) = channel::<int>();
- let t1 = Thread::scoped(move|| {
+ let t1 = thread::spawn(move|| {
tx1.send(()).unwrap();
for _ in 0..40 {
assert_eq!(rx2.recv().unwrap(), 1);
}
});
rx1.recv().unwrap();
- let t2 = Thread::scoped(move|| {
+ let t2 = thread::spawn(move|| {
for _ in 0..40 {
tx2.send(1).unwrap();
}
#[test]
fn recv_from_outside_runtime() {
let (tx, rx) = channel::<int>();
- let t = Thread::scoped(move|| {
+ let t = thread::spawn(move|| {
for _ in 0..40 {
assert_eq!(rx.recv().unwrap(), 1);
}
fn no_runtime() {
let (tx1, rx1) = channel::<int>();
let (tx2, rx2) = channel::<int>();
- let t1 = Thread::scoped(move|| {
+ let t1 = thread::spawn(move|| {
assert_eq!(rx1.recv().unwrap(), 1);
tx2.send(2).unwrap();
});
- let t2 = Thread::scoped(move|| {
+ let t2 = thread::spawn(move|| {
tx1.send(1).unwrap();
assert_eq!(rx2.recv().unwrap(), 2);
});
#[test]
fn oneshot_single_thread_recv_chan_close() {
// Receiving on a closed chan will panic
- let res = Thread::scoped(move|| {
+ let res = thread::spawn(move|| {
let (tx, rx) = channel::<int>();
drop(tx);
rx.recv().unwrap();
#[test]
fn oneshot_multi_task_recv_then_send() {
let (tx, rx) = channel::<Box<int>>();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
assert!(rx.recv().unwrap() == box 10);
});
#[test]
fn oneshot_multi_task_recv_then_close() {
let (tx, rx) = channel::<Box<int>>();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
drop(tx);
});
- let res = Thread::scoped(move|| {
+ let res = thread::spawn(move|| {
assert!(rx.recv().unwrap() == box 10);
}).join();
assert!(res.is_err());
fn oneshot_multi_thread_close_stress() {
for _ in 0..stress_factor() {
let (tx, rx) = channel::<int>();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
drop(rx);
});
drop(tx);
fn oneshot_multi_thread_send_close_stress() {
for _ in 0..stress_factor() {
let (tx, rx) = channel::<int>();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
drop(rx);
});
- let _ = Thread::scoped(move|| {
+ let _ = thread::spawn(move|| {
tx.send(1).unwrap();
}).join();
}
fn oneshot_multi_thread_recv_close_stress() {
for _ in 0..stress_factor() {
let (tx, rx) = channel::<int>();
- Thread::spawn(move|| {
- let res = Thread::scoped(move|| {
+ thread::spawn(move|| {
+ let res = thread::spawn(move|| {
rx.recv().unwrap();
}).join();
assert!(res.is_err());
});
- let _t = Thread::spawn(move|| {
- Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
+ thread::spawn(move|| {
drop(tx);
});
});
fn oneshot_multi_thread_send_recv_stress() {
for _ in 0..stress_factor() {
let (tx, rx) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
tx.send(box 10).unwrap();
});
assert!(rx.recv().unwrap() == box 10);
fn send(tx: Sender<Box<int>>, i: int) {
if i == 10 { return }
- Thread::spawn(move|| {
+ thread::spawn(move|| {
tx.send(box i).unwrap();
send(tx, i + 1);
});
fn recv(rx: Receiver<Box<int>>, i: int) {
if i == 10 { return }
- Thread::spawn(move|| {
+ thread::spawn(move|| {
assert!(rx.recv().unwrap() == box i);
recv(rx, i + 1);
});
let total = stress_factor() + 100;
for _ in 0..total {
let tx = tx.clone();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
tx.send(()).unwrap();
});
}
let (tx, rx) = channel::<int>();
let (total_tx, total_rx) = channel::<int>();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut acc = 0;
for x in rx.iter() {
acc += x;
let (tx, rx) = channel::<int>();
let (count_tx, count_rx) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut count = 0;
for x in rx.iter() {
if count >= 3 {
let (tx1, rx1) = channel::<int>();
let (tx2, rx2) = channel::<()>();
let (tx3, rx3) = channel::<()>();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
rx2.recv().unwrap();
tx1.send(1).unwrap();
tx3.send(()).unwrap();
fn destroy_upgraded_shared_port_when_sender_still_active() {
let (tx, rx) = channel();
let (tx2, rx2) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
rx.recv().unwrap(); // wait on a oneshot
drop(rx); // destroy a shared
tx2.send(()).unwrap();
});
// make sure the other task has gone to sleep
- for _ in 0u..5000 { Thread::yield_now(); }
+ for _ in 0u..5000 { thread::yield_now(); }
// upgrade to a shared chan and send a message
let t = tx.clone();
use prelude::v1::*;
use std::env;
- use thread::Thread;
+ use thread;
use super::*;
pub fn stress_factor() -> uint {
#[test]
fn smoke_threads() {
let (tx, rx) = sync_channel::<int>(0);
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
tx.send(1).unwrap();
});
assert_eq!(rx.recv().unwrap(), 1);
#[test]
fn port_gone_concurrent() {
let (tx, rx) = sync_channel::<int>(0);
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
rx.recv().unwrap();
});
while tx.send(1).is_ok() {}
fn port_gone_concurrent_shared() {
let (tx, rx) = sync_channel::<int>(0);
let tx2 = tx.clone();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
rx.recv().unwrap();
});
while tx.send(1).is_ok() && tx2.send(1).is_ok() {}
#[test]
fn chan_gone_concurrent() {
let (tx, rx) = sync_channel::<int>(0);
- Thread::spawn(move|| {
+ thread::spawn(move|| {
tx.send(1).unwrap();
tx.send(1).unwrap();
});
#[test]
fn stress() {
let (tx, rx) = sync_channel::<int>(0);
- Thread::spawn(move|| {
+ thread::spawn(move|| {
for _ in 0u..10000 { tx.send(1).unwrap(); }
});
for _ in 0u..10000 {
let (tx, rx) = sync_channel::<int>(0);
let (dtx, drx) = sync_channel::<()>(0);
- Thread::spawn(move|| {
+ thread::spawn(move|| {
for _ in 0..AMT * NTHREADS {
assert_eq!(rx.recv().unwrap(), 1);
}
for _ in 0..NTHREADS {
let tx = tx.clone();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
for _ in 0..AMT { tx.send(1).unwrap(); }
});
}
#[test]
fn oneshot_single_thread_recv_chan_close() {
// Receiving on a closed chan will panic
- let res = Thread::scoped(move|| {
+ let res = thread::spawn(move|| {
let (tx, rx) = sync_channel::<int>(0);
drop(tx);
rx.recv().unwrap();
#[test]
fn oneshot_multi_task_recv_then_send() {
let (tx, rx) = sync_channel::<Box<int>>(0);
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
assert!(rx.recv().unwrap() == box 10);
});
#[test]
fn oneshot_multi_task_recv_then_close() {
let (tx, rx) = sync_channel::<Box<int>>(0);
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
drop(tx);
});
- let res = Thread::scoped(move|| {
+ let res = thread::spawn(move|| {
assert!(rx.recv().unwrap() == box 10);
}).join();
assert!(res.is_err());
fn oneshot_multi_thread_close_stress() {
for _ in 0..stress_factor() {
let (tx, rx) = sync_channel::<int>(0);
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
drop(rx);
});
drop(tx);
fn oneshot_multi_thread_send_close_stress() {
for _ in 0..stress_factor() {
let (tx, rx) = sync_channel::<int>(0);
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
drop(rx);
});
- let _ = Thread::scoped(move || {
+ let _ = thread::spawn(move || {
tx.send(1).unwrap();
}).join();
}
fn oneshot_multi_thread_recv_close_stress() {
for _ in 0..stress_factor() {
let (tx, rx) = sync_channel::<int>(0);
- let _t = Thread::spawn(move|| {
- let res = Thread::scoped(move|| {
+ let _t = thread::spawn(move|| {
+ let res = thread::spawn(move|| {
rx.recv().unwrap();
}).join();
assert!(res.is_err());
});
- let _t = Thread::spawn(move|| {
- Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
+ thread::spawn(move|| {
drop(tx);
});
});
fn oneshot_multi_thread_send_recv_stress() {
for _ in 0..stress_factor() {
let (tx, rx) = sync_channel::<Box<int>>(0);
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
tx.send(box 10).unwrap();
});
assert!(rx.recv().unwrap() == box 10);
fn send(tx: SyncSender<Box<int>>, i: int) {
if i == 10 { return }
- Thread::spawn(move|| {
+ thread::spawn(move|| {
tx.send(box i).unwrap();
send(tx, i + 1);
});
fn recv(rx: Receiver<Box<int>>, i: int) {
if i == 10 { return }
- Thread::spawn(move|| {
+ thread::spawn(move|| {
assert!(rx.recv().unwrap() == box i);
recv(rx, i + 1);
});
let total = stress_factor() + 100;
for _ in 0..total {
let tx = tx.clone();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
tx.send(()).unwrap();
});
}
let (tx, rx) = sync_channel::<int>(0);
let (total_tx, total_rx) = sync_channel::<int>(0);
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut acc = 0;
for x in rx.iter() {
acc += x;
let (tx, rx) = sync_channel::<int>(0);
let (count_tx, count_rx) = sync_channel(0);
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let mut count = 0;
for x in rx.iter() {
if count >= 3 {
let (tx1, rx1) = sync_channel::<int>(1);
let (tx2, rx2) = sync_channel::<()>(1);
let (tx3, rx3) = sync_channel::<()>(1);
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
rx2.recv().unwrap();
tx1.send(1).unwrap();
tx3.send(()).unwrap();
fn destroy_upgraded_shared_port_when_sender_still_active() {
let (tx, rx) = sync_channel::<()>(0);
let (tx2, rx2) = sync_channel::<()>(0);
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
rx.recv().unwrap(); // wait on a oneshot
drop(rx); // destroy a shared
tx2.send(()).unwrap();
});
// make sure the other task has gone to sleep
- for _ in 0u..5000 { Thread::yield_now(); }
+ for _ in 0u..5000 { thread::yield_now(); }
// upgrade to a shared chan and send a message
let t = tx.clone();
#[test]
fn send1() {
let (tx, rx) = sync_channel::<int>(0);
- let _t = Thread::spawn(move|| { rx.recv().unwrap(); });
+ let _t = thread::spawn(move|| { rx.recv().unwrap(); });
assert_eq!(tx.send(1), Ok(()));
}
#[test]
fn send2() {
let (tx, rx) = sync_channel::<int>(0);
- let _t = Thread::spawn(move|| { drop(rx); });
+ let _t = thread::spawn(move|| { drop(rx); });
assert!(tx.send(1).is_err());
}
fn send3() {
let (tx, rx) = sync_channel::<int>(1);
assert_eq!(tx.send(1), Ok(()));
- let _t =Thread::spawn(move|| { drop(rx); });
+ let _t =thread::spawn(move|| { drop(rx); });
assert!(tx.send(1).is_err());
}
let tx2 = tx.clone();
let (done, donerx) = channel();
let done2 = done.clone();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
assert!(tx.send(1).is_err());
done.send(()).unwrap();
});
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
assert!(tx2.send(2).is_err());
done2.send(()).unwrap();
});
let (tx1, rx1) = sync_channel::<()>(3);
let (tx2, rx2) = sync_channel::<()>(3);
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
rx1.recv().unwrap();
tx2.try_send(()).unwrap();
});
use sync::mpsc::channel;
use super::{Queue, Data, Empty, Inconsistent};
use sync::Arc;
- use thread::Thread;
+ use thread;
#[test]
fn test_full() {
for _ in 0..nthreads {
let tx = tx.clone();
let q = q.clone();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
for i in 0..nmsgs {
q.push(i);
}
mod test {
use prelude::v1::*;
- use thread::Thread;
+ use thread;
use sync::mpsc::*;
// Don't use the libstd version so we can pull in the right Select structure
let (_tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<int>();
- let _t = Thread::spawn(move|| {
- for _ in 0u..20 { Thread::yield_now(); }
+ let _t = thread::spawn(move|| {
+ for _ in 0u..20 { thread::yield_now(); }
tx1.send(1).unwrap();
rx3.recv().unwrap();
- for _ in 0u..20 { Thread::yield_now(); }
+ for _ in 0u..20 { thread::yield_now(); }
});
select! {
let (tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<()>();
- let _t = Thread::spawn(move|| {
- for _ in 0u..20 { Thread::yield_now(); }
+ let _t = thread::spawn(move|| {
+ for _ in 0u..20 { thread::yield_now(); }
tx1.send(1).unwrap();
tx2.send(2).unwrap();
rx3.recv().unwrap();
let (tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<()>();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
for i in 0..AMT {
if i % 2 == 0 {
tx1.send(i).unwrap();
let (_tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<()>();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
rx3.recv().unwrap();
tx1.clone();
assert_eq!(rx3.try_recv(), Err(TryRecvError::Empty));
let (_tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<()>();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
rx3.recv().unwrap();
tx1.clone();
assert_eq!(rx3.try_recv(), Err(TryRecvError::Empty));
let (tx1, rx1) = channel::<()>();
let (tx2, rx2) = channel::<()>();
let (tx3, rx3) = channel::<()>();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let s = Select::new();
let mut h1 = s.handle(&rx1);
let mut h2 = s.handle(&rx2);
tx3.send(()).unwrap();
});
- for _ in 0u..1000 { Thread::yield_now(); }
+ for _ in 0u..1000 { thread::yield_now(); }
drop(tx1.clone());
tx2.send(()).unwrap();
rx3.recv().unwrap();
fn oneshot_data_waiting() {
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
select! {
_n = rx1.recv() => {}
}
tx2.send(()).unwrap();
});
- for _ in 0u..100 { Thread::yield_now() }
+ for _ in 0u..100 { thread::yield_now() }
tx1.send(()).unwrap();
rx2.recv().unwrap();
}
tx1.send(()).unwrap();
rx1.recv().unwrap();
rx1.recv().unwrap();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
select! {
_n = rx1.recv() => {}
}
tx2.send(()).unwrap();
});
- for _ in 0u..100 { Thread::yield_now() }
+ for _ in 0u..100 { thread::yield_now() }
tx1.send(()).unwrap();
rx2.recv().unwrap();
}
drop(tx1.clone());
tx1.send(()).unwrap();
rx1.recv().unwrap();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
select! {
_n = rx1.recv() => {}
}
tx2.send(()).unwrap();
});
- for _ in 0u..100 { Thread::yield_now() }
+ for _ in 0u..100 { thread::yield_now() }
tx1.send(()).unwrap();
rx2.recv().unwrap();
}
#[test]
fn sync2() {
let (tx, rx) = sync_channel::<int>(0);
- let _t = Thread::spawn(move|| {
- for _ in 0u..100 { Thread::yield_now() }
+ let _t = thread::spawn(move|| {
+ for _ in 0u..100 { thread::yield_now() }
tx.send(1).unwrap();
});
select! {
fn sync3() {
let (tx1, rx1) = sync_channel::<int>(0);
let (tx2, rx2): (Sender<int>, Receiver<int>) = channel();
- let _t = Thread::spawn(move|| { tx1.send(1).unwrap(); });
- let _t = Thread::spawn(move|| { tx2.send(2).unwrap(); });
+ let _t = thread::spawn(move|| { tx1.send(1).unwrap(); });
+ let _t = thread::spawn(move|| { tx2.send(2).unwrap(); });
select! {
n = rx1.recv() => {
let n = n.unwrap();
use sync::mpsc::select::StartResult::*;
use sync::mpsc::select::StartResult;
use sync::{Mutex, MutexGuard};
-use thread::Thread;
+use thread;
const DISCONNECTED: isize = isize::MIN;
const FUDGE: isize = 1024;
match self.queue.pop() {
mpsc::Data(..) => {}
mpsc::Empty => break,
- mpsc::Inconsistent => Thread::yield_now(),
+ mpsc::Inconsistent => thread::yield_now(),
}
}
// maybe we're done, if we're not the last ones
mpsc::Inconsistent => {
let data;
loop {
- Thread::yield_now();
+ thread::yield_now();
match self.queue.pop() {
mpsc::Data(t) => { data = t; break }
mpsc::Empty => panic!("inconsistent => empty"),
drop(self.take_to_wake());
} else {
while self.to_wake.load(Ordering::SeqCst) != 0 {
- Thread::yield_now();
+ thread::yield_now();
}
}
// if the number of steals is -1, it was the pre-emptive -1 steal
use sync::Arc;
use super::Queue;
- use thread::Thread;
+ use thread;
use sync::mpsc::channel;
#[test]
let (tx, rx) = channel();
let q2 = q.clone();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
for _ in 0u..100000 {
loop {
match q2.pop() {
use core::cmp;
use core::isize;
-use thread::Thread;
+use thread;
use sync::atomic::{AtomicIsize, AtomicUsize, Ordering, AtomicBool};
use sync::mpsc::Receiver;
drop(self.take_to_wake());
} else {
while self.to_wake.load(Ordering::SeqCst) != 0 {
- Thread::yield_now();
+ thread::yield_now();
}
}
assert_eq!(self.steals, 0);
///
/// ```rust
/// use std::sync::{Arc, Mutex};
-/// use std::thread::Thread;
+/// use std::thread;
/// use std::sync::mpsc::channel;
///
/// const N: uint = 10;
/// let (tx, rx) = channel();
/// for _ in 0u..10 {
/// let (data, tx) = (data.clone(), tx.clone());
-/// Thread::spawn(move || {
+/// thread::spawn(move || {
/// // The shared static can only be accessed once the lock is held.
/// // Our non-atomic increment is safe because we're the only thread
/// // which can access the shared state when the lock is held.
///
/// ```rust
/// use std::sync::{Arc, Mutex};
-/// use std::thread::Thread;
+/// use std::thread;
///
/// let lock = Arc::new(Mutex::new(0u));
/// let lock2 = lock.clone();
///
-/// let _ = Thread::scoped(move || -> () {
+/// let _ = thread::spawn(move || -> () {
/// // This thread will acquire the mutex first, unwrapping the result of
/// // `lock` because the lock has not been poisoned.
/// let _lock = lock2.lock().unwrap();
use sync::mpsc::channel;
use sync::{Arc, Mutex, StaticMutex, MUTEX_INIT, Condvar};
- use thread::Thread;
+ use thread;
struct Packet<T>(Arc<(Mutex<T>, Condvar)>);
let (tx, rx) = channel();
for _ in 0..K {
let tx2 = tx.clone();
- Thread::spawn(move|| { inc(); tx2.send(()).unwrap(); });
+ thread::spawn(move|| { inc(); tx2.send(()).unwrap(); });
let tx2 = tx.clone();
- Thread::spawn(move|| { inc(); tx2.send(()).unwrap(); });
+ thread::spawn(move|| { inc(); tx2.send(()).unwrap(); });
}
drop(tx);
let packet = Packet(Arc::new((Mutex::new(false), Condvar::new())));
let packet2 = Packet(packet.0.clone());
let (tx, rx) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
// wait until parent gets in
rx.recv().unwrap();
let &(ref lock, ref cvar) = &*packet2.0;
let packet2 = Packet(packet.0.clone());
let (tx, rx) = channel();
- let _t = Thread::spawn(move || -> () {
+ let _t = thread::spawn(move || -> () {
rx.recv().unwrap();
let &(ref lock, ref cvar) = &*packet2.0;
let _g = lock.lock().unwrap();
let arc = Arc::new(Mutex::new(1));
assert!(!arc.is_poisoned());
let arc2 = arc.clone();
- let _ = Thread::scoped(move|| {
+ let _ = thread::spawn(move|| {
let lock = arc2.lock().unwrap();
assert_eq!(*lock, 2);
}).join();
let arc = Arc::new(Mutex::new(1));
let arc2 = Arc::new(Mutex::new(arc));
let (tx, rx) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let lock = arc2.lock().unwrap();
let lock2 = lock.lock().unwrap();
assert_eq!(*lock2, 1);
fn test_mutex_arc_access_in_unwind() {
let arc = Arc::new(Mutex::new(1));
let arc2 = arc.clone();
- let _ = Thread::scoped(move|| -> () {
+ let _ = thread::spawn(move|| -> () {
struct Unwinder {
i: Arc<Mutex<int>>,
}
mod test {
use prelude::v1::*;
- use thread::Thread;
+ use thread;
use super::{ONCE_INIT, Once};
use sync::mpsc::channel;
let (tx, rx) = channel();
for _ in 0u..10 {
let tx = tx.clone();
- Thread::spawn(move|| {
- for _ in 0u..4 { Thread::yield_now() }
+ thread::spawn(move|| {
+ for _ in 0u..4 { thread::yield_now() }
unsafe {
O.call_once(|| {
assert!(!run);
use cell::UnsafeCell;
use error::{Error, FromError};
use fmt;
-use thread::Thread;
+use thread;
pub struct Flag { failed: UnsafeCell<bool> }
pub const FLAG_INIT: Flag = Flag { failed: UnsafeCell { value: false } };
impl Flag {
#[inline]
pub fn borrow(&self) -> LockResult<Guard> {
- let ret = Guard { panicking: Thread::panicking() };
+ let ret = Guard { panicking: thread::panicking() };
if unsafe { *self.failed.get() } {
Err(PoisonError::new(ret))
} else {
#[inline]
pub fn done(&self, guard: &Guard) {
- if !guard.panicking && Thread::panicking() {
+ if !guard.panicking && thread::panicking() {
unsafe { *self.failed.get() = true; }
}
}
use rand::{self, Rng};
use sync::mpsc::channel;
- use thread::Thread;
+ use thread;
use sync::{Arc, RwLock, StaticRwLock, RW_LOCK_INIT};
#[test]
let (tx, rx) = channel::<()>();
for _ in 0..N {
let tx = tx.clone();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
let mut rng = rand::thread_rng();
for _ in 0..M {
if rng.gen_weighted_bool(N) {
fn test_rw_arc_poison_wr() {
let arc = Arc::new(RwLock::new(1));
let arc2 = arc.clone();
- let _: Result<uint, _> = Thread::scoped(move|| {
+ let _: Result<uint, _> = thread::spawn(move|| {
let _lock = arc2.write().unwrap();
panic!();
}).join();
let arc = Arc::new(RwLock::new(1));
assert!(!arc.is_poisoned());
let arc2 = arc.clone();
- let _: Result<uint, _> = Thread::scoped(move|| {
+ let _: Result<uint, _> = thread::spawn(move|| {
let _lock = arc2.write().unwrap();
panic!();
}).join();
fn test_rw_arc_no_poison_rr() {
let arc = Arc::new(RwLock::new(1));
let arc2 = arc.clone();
- let _: Result<uint, _> = Thread::scoped(move|| {
+ let _: Result<uint, _> = thread::spawn(move|| {
let _lock = arc2.read().unwrap();
panic!();
}).join();
fn test_rw_arc_no_poison_rw() {
let arc = Arc::new(RwLock::new(1));
let arc2 = arc.clone();
- let _: Result<uint, _> = Thread::scoped(move|| {
+ let _: Result<uint, _> = thread::spawn(move|| {
let _lock = arc2.read().unwrap();
panic!()
}).join();
let arc2 = arc.clone();
let (tx, rx) = channel();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
let mut lock = arc2.write().unwrap();
for _ in 0u..10 {
let tmp = *lock;
*lock = -1;
- Thread::yield_now();
+ thread::yield_now();
*lock = tmp + 1;
}
tx.send(()).unwrap();
let mut children = Vec::new();
for _ in 0u..5 {
let arc3 = arc.clone();
- children.push(Thread::scoped(move|| {
+ children.push(thread::spawn(move|| {
let lock = arc3.read().unwrap();
assert!(*lock >= 0);
}));
fn test_rw_arc_access_in_unwind() {
let arc = Arc::new(RwLock::new(1));
let arc2 = arc.clone();
- let _ = Thread::scoped(move|| -> () {
+ let _ = thread::spawn(move|| -> () {
struct Unwinder {
i: Arc<RwLock<int>>,
}
use sync::Arc;
use super::Semaphore;
use sync::mpsc::channel;
- use thread::Thread;
+ use thread;
#[test]
fn test_sem_acquire_release() {
fn test_sem_as_mutex() {
let s = Arc::new(Semaphore::new(1));
let s2 = s.clone();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let _g = s2.access();
});
let _g = s.access();
let (tx, rx) = channel();
let s = Arc::new(Semaphore::new(0));
let s2 = s.clone();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
s2.acquire();
tx.send(()).unwrap();
});
let (tx, rx) = channel();
let s = Arc::new(Semaphore::new(0));
let s2 = s.clone();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
s2.release();
let _ = rx.recv();
});
let s2 = s.clone();
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let _g = s2.access();
let _ = rx2.recv();
tx1.send(()).unwrap();
let (tx, rx) = channel();
{
let _g = s.access();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
tx.send(()).unwrap();
drop(s2.access());
tx.send(()).unwrap();
use sync::{Arc, Mutex};
use sync::mpsc::{channel, Sender, Receiver};
-use thread::Thread;
+use thread;
use thunk::Thunk;
struct Sentinel<'a> {
}
fn spawn_in_pool(jobs: Arc<Mutex<Receiver<Thunk>>>) {
- Thread::spawn(move || {
+ thread::spawn(move || {
// Will spawn a new thread on panic unless it is cancelled.
let sentinel = Sentinel::new(&jobs);
use sync::mpsc::{channel, Sender, Receiver};
use sys::helper_signal;
-use thread::Thread;
+use thread;
/// A structure for management of a helper thread.
///
let receive = RaceBox(receive);
let t = f();
- Thread::spawn(move || {
+ thread::spawn(move || {
helper(receive.0, rx, t);
let _g = self.lock.lock().unwrap();
*self.shutdown.get() = true;
impl ThreadInfo {
fn with<R, F>(f: F) -> R where F: FnOnce(&mut ThreadInfo) -> R {
if THREAD_INFO.state() == State::Destroyed {
- panic!("Use of std::thread::Thread::current() is not possible after \
+ panic!("Use of std::thread::current() is not possible after \
the thread's local data has been destroyed");
}
}));
}
-// a hack to get around privacy restrictions; implemented by `std::thread::Thread`
+// a hack to get around privacy restrictions; implemented by `std::thread`
pub trait NewThread {
fn new(name: Option<String>) -> Self;
}
//! # Usage
//!
//! This module should likely not be used directly unless other primitives are
-//! being built on. types such as `thread_local::scoped::Key` are likely much
+//! being built on. types such as `thread_local::spawn::Key` are likely much
//! more useful in practice than this OS-based version which likely requires
//! unsafe code to interoperate with.
//!
//! Already-running threads are represented via the `Thread` type, which you can
//! get in one of two ways:
//!
-//! * By spawning a new thread, e.g. using the `Thread::spawn` constructor;
-//! * By requesting the current thread, using the `Thread::current` function.
+//! * By spawning a new thread, e.g. using the `thread::spawn` constructor;
+//! * By requesting the current thread, using the `thread::current` function.
//!
//! Threads can be named, and provide some built-in support for low-level
//! synchronization described below.
//!
-//! The `Thread::current()` function is available even for threads not spawned
+//! The `thread::current()` function is available even for threads not spawned
//! by the APIs of this module.
//!
//! ## Spawning a thread
//!
-//! A new thread can be spawned using the `Thread::spawn` function:
+//! A new thread can be spawned using the `thread::spawn` function:
//!
//! ```rust
-//! use std::thread::Thread;
+//! use std::thread;
//!
-//! Thread::spawn(move || {
+//! thread::spawn(move || {
//! println!("Hello, World!");
//! // some computation here
//! });
//! For this scenario, use the `scoped` constructor:
//!
//! ```rust
-//! use std::thread::Thread;
+//! use std::thread;
//!
-//! let guard = Thread::scoped(move || {
+//! let guard = thread::scoped(move || {
//! println!("Hello, World!");
//! // some computation here
//! });
//! // do some other work in the meantime
-//! let result = guard.join();
+//! let output = guard.join();
//! ```
//!
//! The `scoped` function doesn't return a `Thread` directly; instead,
//! Conceptually, each `Thread` handle has an associated token, which is
//! initially not present:
//!
-//! * The `Thread::park()` function blocks the current thread unless or until
+//! * The `thread::park()` function blocks the current thread unless or until
//! the token is available for its thread handle, at which point It atomically
//! consumes the token. It may also return *spuriously*, without consuming the
-//! token. `Thread::park_timeout()` does the same, but allows specifying a
+//! token. `thread::park_timeout()` does the same, but allows specifying a
//! maximum time to block the thread for.
//!
//! * The `unpark()` method on a `Thread` atomically makes the token available
// or futuxes, and in either case may allow spurious wakeups.
#[stable(feature = "rust1", since = "1.0.0")]
pub fn park() {
- let thread = Thread::current();
+ let thread = current();
let mut guard = thread.inner.lock.lock().unwrap();
while !*guard {
guard = thread.inner.cvar.wait(guard).unwrap();
/// See the module doc for more detail.
#[unstable(feature = "std_misc", reason = "recently introduced, depends on Duration")]
pub fn park_timeout(dur: Duration) {
- let thread = Thread::current();
+ let thread = current();
let mut guard = thread.inner.lock.lock().unwrap();
if !*guard {
let (g, _) = thread.inner.cvar.wait_timeout(guard, dur).unwrap();
#[deprecated(since = "1.0.0", reason = "use module-level free fucntion")]
#[unstable(feature = "std_misc", reason = "recently introduced")]
pub fn park() {
- let thread = Thread::current();
+ let thread = current();
let mut guard = thread.inner.lock.lock().unwrap();
while !*guard {
guard = thread.inner.cvar.wait(guard).unwrap();
#[deprecated(since = "1.0.0", reason = "use module-level free fucntion")]
#[unstable(feature = "std_misc", reason = "recently introduced")]
pub fn park_timeout(dur: Duration) {
- let thread = Thread::current();
+ let thread = current();
let mut guard = thread.inner.lock.lock().unwrap();
if !*guard {
let (g, _) = thread.inner.cvar.wait_timeout(guard, dur).unwrap();
use boxed::BoxAny;
use result;
use std::old_io::{ChanReader, ChanWriter};
- use super::{Thread, Builder};
+ use super::{self, Thread, Builder};
use thunk::Thunk;
use time::Duration;
#[test]
fn test_unnamed_thread() {
- Thread::scoped(move|| {
- assert!(Thread::current().name().is_none());
+ thread::spawn(move|| {
+ assert!(thread::current().name().is_none());
}).join().ok().unwrap();
}
#[test]
fn test_named_thread() {
Builder::new().name("ada lovelace".to_string()).scoped(move|| {
- assert!(Thread::current().name().unwrap() == "ada lovelace".to_string());
+ assert!(thread::current().name().unwrap() == "ada lovelace".to_string());
}).join().ok().unwrap();
}
#[test]
fn test_run_basic() {
let (tx, rx) = channel();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
tx.send(()).unwrap();
});
rx.recv().unwrap();
#[test]
fn test_join_success() {
- match Thread::scoped(move|| -> String {
+ match thread::spawn(move|| -> String {
"Success!".to_string()
}).join().as_ref().map(|s| &**s) {
result::Result::Ok("Success!") => (),
#[test]
fn test_join_panic() {
- match Thread::scoped(move|| {
+ match thread::spawn(move|| {
panic!()
}).join() {
result::Result::Err(_) => (),
}
}
+ #[test]
+ fn test_scoped_success() {
+ let res = thread::scoped(move|| -> String {
+ "Success!".to_string()
+ }).join();
+ assert!(res == "Success!");
+ }
+
+ #[test]
+ #[should_fail]
+ fn test_scoped_panic() {
+ thread::scoped(|| panic!()).join();
+ }
+
+ #[test]
+ #[should_fail]
+ fn test_scoped_implicit_panic() {
+ thread::scoped(|| panic!());
+ }
+
#[test]
fn test_spawn_sched() {
use clone::Clone;
fn f(i: int, tx: Sender<()>) {
let tx = tx.clone();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
if i == 0 {
tx.send(()).unwrap();
} else {
fn test_spawn_sched_childs_on_default_sched() {
let (tx, rx) = channel();
- Thread::spawn(move|| {
- Thread::spawn(move|| {
+ thread::spawn(move|| {
+ thread::spawn(move|| {
tx.send(()).unwrap();
});
});
#[test]
fn test_avoid_copying_the_body_spawn() {
avoid_copying_the_body(|v| {
- Thread::spawn(move || v.invoke(()));
+ thread::spawn(move || v.invoke(()));
});
}
#[test]
fn test_avoid_copying_the_body_thread_spawn() {
avoid_copying_the_body(|f| {
- Thread::spawn(move|| {
+ thread::spawn(move|| {
f.invoke(());
});
})
#[test]
fn test_avoid_copying_the_body_join() {
avoid_copying_the_body(|f| {
- let _ = Thread::scoped(move|| {
+ let _ = thread::spawn(move|| {
f.invoke(())
}).join();
})
fn child_no(x: uint) -> Thunk {
return Thunk::new(move|| {
if x < GENERATIONS {
- Thread::spawn(move|| child_no(x+1).invoke(()));
+ thread::spawn(move|| child_no(x+1).invoke(()));
}
});
}
- Thread::spawn(|| child_no(0).invoke(()));
+ thread::spawn(|| child_no(0).invoke(()));
}
#[test]
fn test_simple_newsched_spawn() {
- Thread::spawn(move || {});
+ thread::spawn(move || {});
}
#[test]
fn test_try_panic_message_static_str() {
- match Thread::scoped(move|| {
+ match thread::spawn(move|| {
panic!("static string");
}).join() {
Err(e) => {
#[test]
fn test_try_panic_message_owned_str() {
- match Thread::scoped(move|| {
+ match thread::spawn(move|| {
panic!("owned string".to_string());
}).join() {
Err(e) => {
#[test]
fn test_try_panic_message_any() {
- match Thread::scoped(move|| {
+ match thread::spawn(move|| {
panic!(box 413u16 as Box<Any + Send>);
}).join() {
Err(e) => {
fn test_try_panic_message_unit_struct() {
struct Juju;
- match Thread::scoped(move|| {
+ match thread::spawn(move|| {
panic!(Juju)
}).join() {
Err(ref e) if e.is::<Juju>() => {}
#[test]
fn test_park_timeout_unpark_before() {
for _ in 0..10 {
- Thread::current().unpark();
- Thread::park_timeout(Duration::seconds(10_000_000));
+ thread::current().unpark();
+ thread::park_timeout(Duration::seconds(10_000_000));
}
}
#[test]
fn test_park_timeout_unpark_not_called() {
for _ in 0..10 {
- Thread::park_timeout(Duration::milliseconds(10));
+ thread::park_timeout(Duration::milliseconds(10));
}
}
use std::old_io;
for _ in 0..10 {
- let th = Thread::current();
+ let th = thread::current();
- let _guard = Thread::scoped(move || {
+ let _guard = thread::spawn(move || {
old_io::timer::sleep(Duration::milliseconds(50));
th.unpark();
});
- Thread::park_timeout(Duration::seconds(10_000_000));
+ thread::park_timeout(Duration::seconds(10_000_000));
}
}
///
/// ```
/// use std::cell::RefCell;
-/// use std::thread::Thread;
+/// use std::thread;
///
/// thread_local!(static FOO: RefCell<uint> = RefCell::new(1));
///
/// });
///
/// // each thread starts out with the initial value of 1
-/// Thread::spawn(move|| {
+/// thread::spawn(move|| {
/// FOO.with(|f| {
/// assert_eq!(*f.borrow(), 1);
/// *f.borrow_mut() = 3;
use sync::mpsc::{channel, Sender};
use cell::UnsafeCell;
use super::State;
- use thread::Thread;
+ use thread;
struct Foo(Sender<()>);
*f.get() = 2;
});
let (tx, rx) = channel();
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
FOO.with(|f| unsafe {
assert_eq!(*f.get(), 1);
});
}
thread_local!(static FOO: Foo = foo());
- Thread::scoped(|| {
+ thread::spawn(|| {
assert!(FOO.state() == State::Uninitialized);
FOO.with(|_| {
assert!(FOO.state() == State::Valid);
});
let (tx, rx) = channel();
- let _t = Thread::spawn(move|| unsafe {
+ let _t = thread::spawn(move|| unsafe {
let mut tx = Some(tx);
FOO.with(|f| {
*f.get() = Some(Foo(tx.take().unwrap()));
}
}
- Thread::scoped(move|| {
+ thread::spawn(move|| {
drop(S1);
}).join().ok().unwrap();
}
}
}
- Thread::scoped(move|| unsafe {
+ thread::spawn(move|| unsafe {
K1.with(|s| *s.get() = Some(S1));
}).join().ok().unwrap();
}
}
let (tx, rx) = channel();
- let _t = Thread::spawn(move|| unsafe {
+ let _t = thread::spawn(move|| unsafe {
let mut tx = Some(tx);
K1.with(|s| *s.get() = Some(S1(tx.take().unwrap())));
});
target_os = "openbsd",
target_arch = "aarch64")),
thread_local)]
- static $name: ::std::thread_local::scoped::Key<$t> =
+ static $name: ::std::thread_local::spawn::Key<$t> =
__scoped_thread_local_inner!($t);
);
(pub static $name:ident: $t:ty) => (
target_os = "openbsd",
target_arch = "aarch64")),
thread_local)]
- pub static $name: ::std::thread_local::scoped::Key<$t> =
+ pub static $name: ::std::thread_local::spawn::Key<$t> =
__scoped_thread_local_inner!($t);
);
($t:ty) => ({
- use std::thread_local::scoped::Key as __Key;
+ use std::thread_local::spawn::Key as __Key;
#[cfg(not(any(windows,
target_os = "android",
target_os = "openbsd",
target_arch = "aarch64")))]
const _INIT: __Key<$t> = __Key {
- inner: ::std::thread_local::scoped::__impl::KeyInner {
+ inner: ::std::thread_local::spawn::__impl::KeyInner {
inner: ::std::cell::UnsafeCell { value: 0 as *mut _ },
}
};
target_os = "openbsd",
target_arch = "aarch64"))]
const _INIT: __Key<$t> = __Key {
- inner: ::std::thread_local::scoped::__impl::KeyInner {
- inner: ::std::thread_local::scoped::__impl::OS_INIT,
+ inner: ::std::thread_local::spawn::__impl::KeyInner {
+ inner: ::std::thread_local::spawn::__impl::OS_INIT,
marker: ::std::marker::InvariantType,
}
};
monitor_ch: Sender<MonitorMsg>,
nocapture: bool,
testfn: Thunk) {
- Thread::spawn(move || {
+ thread::spawn(move || {
let (tx, rx) = channel();
let mut reader = ChanReader::new(rx);
let stdout = ChanWriter::new(tx.clone());
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::thread::Thread;
+use std::thread;
use std::sync::mpsc::{Receiver, channel};
pub fn foo<T:Send + Clone>(x: T) -> Receiver<T> {
let (tx, rx) = channel();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
tx.send(x.clone());
});
rx
use std::sync::mpsc::{channel, Sender, Receiver};
use std::os;
use std::env;
-use std::thread::Thread;
+use std::thread;
use std::time::Duration;
fn move_out<T>(_x: T) {}
let mut worker_results = Vec::new();
for _ in 0u..workers {
let to_child = to_child.clone();
- worker_results.push(Thread::scoped(move|| {
+ worker_results.push(thread::spawn(move|| {
for _ in 0u..size / workers {
//println!("worker {}: sending {} bytes", i, num_bytes);
to_child.send(request::bytes(num_bytes)).unwrap();
//println!("worker {} exiting", i);
}));
}
- Thread::spawn(move|| {
+ thread::spawn(move|| {
server(&from_parent, &to_parent);
});
use std::sync::mpsc::{channel, Sender, Receiver};
use std::os;
use std::env;
-use std::thread::Thread;
+use std::thread;
use std::time::Duration;
enum request {
let mut worker_results = Vec::new();
let from_parent = if workers == 1 {
let (to_child, from_parent) = channel();
- worker_results.push(Thread::scoped(move|| {
+ worker_results.push(thread::spawn(move|| {
for _ in 0u..size / workers {
//println!("worker {}: sending {} bytes", i, num_bytes);
to_child.send(request::bytes(num_bytes));
let (to_child, from_parent) = channel();
for _ in 0u..workers {
let to_child = to_child.clone();
- worker_results.push(Thread::scoped(move|| {
+ worker_results.push(thread::spawn(move|| {
for _ in 0u..size / workers {
//println!("worker {}: sending {} bytes", i, num_bytes);
to_child.send(request::bytes(num_bytes));
}
from_parent
};
- Thread::spawn(move|| {
+ thread::spawn(move|| {
server(&from_parent, &to_parent);
});
use std::sync::mpsc::channel;
use std::os;
-use std::thread::Thread;
+use std::thread;
// This is a simple bench that creates M pairs of tasks. These
// tasks ping-pong back and forth over a pair of streams. This is a
// Create a channel: B->A
let (btx, brx) = channel();
- let guard_a = Thread::scoped(move|| {
+ let guard_a = thread::spawn(move|| {
let (tx, rx) = (atx, brx);
for _ in 0..n {
tx.send(()).unwrap();
}
});
- let guard_b = Thread::scoped(move|| {
+ let guard_b = thread::spawn(move|| {
let (tx, rx) = (btx, arx);
for _ in 0..n {
rx.recv().unwrap();
use std::sync::mpsc::channel;
use std::os;
-use std::thread::Thread;
+use std::thread;
// A simple implementation of parfib. One subtree is found in a new
// task and communicated over a oneshot pipe, the other is found
}
let (tx, rx) = channel();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
tx.send(parfib(n-1)).unwrap();
});
let m2 = parfib(n-2);
let messages = range_step(min_depth, max_depth + 1, 2).map(|depth| {
use std::num::Int;
let iterations = 2.pow((max_depth - depth + min_depth) as usize);
- Thread::scoped(move || inner(depth, iterations))
+ thread::spawn(move || inner(depth, iterations))
}).collect::<Vec<_>>();
for message in messages {
use self::Color::{Red, Yellow, Blue};
use std::sync::mpsc::{channel, Sender, Receiver};
use std::fmt;
-use std::thread::Thread;
+use std::thread;
fn print_complements() {
let all = [Blue, Red, Yellow];
let to_rendezvous = to_rendezvous.clone();
let to_rendezvous_log = to_rendezvous_log.clone();
let (to_creature, from_rendezvous) = channel();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
creature(ii,
col,
from_rendezvous,
// OF THE POSSIBILITY OF SUCH DAMAGE.
use std::{cmp, iter, mem};
-use std::thread::Thread;
+use std::thread;
fn rotate(x: &mut [i32]) {
let mut prev = x[0];
for (_, j) in (0..N).zip(iter::count(0, k)) {
let max = cmp::min(j+k, perm.max());
- futures.push(Thread::scoped(move|| {
+ futures.push(thread::spawn(move|| {
work(perm, j as uint, max as uint)
}))
}
use std::os;
use std::env;
use std::sync::mpsc::{channel, Sender, Receiver};
-use std::thread::Thread;
+use std::thread;
fn f64_cmp(x: f64, y: f64) -> Ordering {
// arbitrarily decide that NaNs are larger than everything.
let (to_child, from_parent) = channel();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
make_sequence_processor(sz, &from_parent, &to_parent_);
});
use std::ascii::OwnedAsciiExt;
use std::slice;
use std::sync::Arc;
-use std::thread::Thread;
+use std::thread;
static TABLE: [u8;4] = [ 'A' as u8, 'C' as u8, 'G' as u8, 'T' as u8 ];
static TABLE_SIZE: uint = 2 << 16;
let nb_freqs: Vec<_> = (1u..3).map(|i| {
let input = input.clone();
- (i, Thread::scoped(move|| generate_frequencies(&input, i)))
+ (i, thread::spawn(move|| generate_frequencies(&input, i)))
}).collect();
let occ_freqs: Vec<_> = OCCURRENCES.iter().map(|&occ| {
let input = input.clone();
- Thread::scoped(move|| generate_frequencies(&input, occ.len()))
+ thread::spawn(move|| generate_frequencies(&input, occ.len()))
}).collect();
for (i, freq) in nb_freqs {
use std::os;
use std::simd::f64x2;
use std::sync::Arc;
-use std::thread::Thread;
+use std::thread;
const ITER: usize = 50;
const LIMIT: f64 = 2.0;
let mut precalc_i = Vec::with_capacity(h);
let precalc_futures = (0..WORKERS).map(|i| {
- Thread::scoped(move|| {
+ thread::spawn(move|| {
let mut rs = Vec::with_capacity(w / WORKERS);
let mut is = Vec::with_capacity(w / WORKERS);
let vec_init_r = arc_init_r.clone();
let vec_init_i = arc_init_i.clone();
- Thread::scoped(move|| {
+ thread::spawn(move|| {
let mut res: Vec<u8> = Vec::with_capacity((chunk_size * w) / 8);
let init_r_slice = vec_init_r;
use std::iter::repeat;
use std::sync::Arc;
use std::sync::mpsc::channel;
-use std::thread::Thread;
+use std::thread;
//
// Utilities.
let masks = masks.clone();
let tx = tx.clone();
let m = *m;
- Thread::spawn(move|| {
+ thread::spawn(move|| {
let mut data = Data::new();
search(&*masks, m, 1, List::Cons(m, &List::Nil), &mut data);
tx.send(data).unwrap();
use std::os;
use std::env;
use std::result::Result::{Ok, Err};
-use std::thread::Thread;
+use std::thread;
use std::time::Duration;
fn fib(n: int) -> int {
} else {
let (tx1, rx) = channel();
let tx2 = tx1.clone();
- Thread::spawn(move|| pfib(&tx2, n - 1));
+ thread::spawn(move|| pfib(&tx2, n - 1));
let tx2 = tx1.clone();
- Thread::spawn(move|| pfib(&tx2, n - 2));
+ thread::spawn(move|| pfib(&tx2, n - 2));
tx.send(rx.recv().unwrap() + rx.recv().unwrap());
}
}
let (tx, rx) = channel();
- Thread::spawn(move|| pfib(&tx, n) );
+ thread::spawn(move|| pfib(&tx, n) );
rx.recv().unwrap()
}
fn stress(num_tasks: int) {
let mut results = Vec::new();
for i in 0..num_tasks {
- results.push(Thread::scoped(move|| {
+ results.push(thread::spawn(move|| {
stress_task(i);
}));
}
use std::old_io::stdio::{stdin_raw, stdout_raw};
use std::old_io::{IoResult, EndOfFile};
use std::ptr::{copy_memory, Unique};
-use std::thread::Thread;
+use std::thread;
struct Tables {
table8: [u8;1 << 8],
// boundary.
let f = Racy(&f as *const F as *const uint);
let raw = Racy(chunk.repr());
- Thread::scoped(move|| {
+ thread::spawn(move|| {
let f = f.0 as *const F;
unsafe { (*f)(mem::transmute(raw.0)) }
})
#![feature(unboxed_closures)]
use std::iter::{repeat, AdditiveIterator};
-use std::thread::Thread;
+use std::thread;
use std::mem;
use std::num::Float;
use std::os;
// boundary.
let f = Racy(&f as *const _ as *const uint);
let raw = Racy(chunk.repr());
- Thread::scoped(move|| {
+ thread::spawn(move|| {
let f = f.0 as *const F;
unsafe { (*f)(i * size, mem::transmute(raw.0)) }
})
// OF THE POSSIBILITY OF SUCH DAMAGE.
use std::sync::mpsc::{channel, Sender, Receiver};
-use std::thread::Thread;
+use std::thread;
fn start(n_tasks: i32, token: i32) {
let (tx, mut rx) = channel();
for i in 2 .. n_tasks + 1 {
let (tx, next_rx) = channel();
let cur_rx = std::mem::replace(&mut rx, next_rx);
- guards.push(Thread::scoped(move|| roundtrip(i, tx, cur_rx)));
+ guards.push(thread::spawn(move|| roundtrip(i, tx, cur_rx)));
}
- let guard = Thread::scoped(move|| roundtrip(1, tx, rx));
+ let guard = thread::spawn(move|| roundtrip(1, tx, rx));
}
fn roundtrip(id: i32, tx: Sender<i32>, rx: Receiver<i32>) {
#![feature(unsafe_destructor, box_syntax)]
use std::env;
-use std::thread::Thread;
+use std::thread;
use std::time::Duration;
#[derive(Clone)]
fn run(repeat: int, depth: int) {
for _ in 0..repeat {
let dur = Duration::span(|| {
- let _ = Thread::scoped(move|| {
+ let _ = thread::spawn(move|| {
recurse_or_panic(depth, None)
}).join();
});
use std::sync::mpsc::{channel, Sender};
use std::os;
use std::env;
-use std::thread::Thread;
+use std::thread;
fn child_generation(gens_left: uint, tx: Sender<()>) {
// This used to be O(n^2) in the number of generations that ever existed.
// With this code, only as many generations are alive at a time as tasks
// alive at a time,
- Thread::spawn(move|| {
+ thread::spawn(move|| {
if gens_left & 1 == 1 {
- Thread::yield_now(); // shake things up a bit
+ thread::yield_now(); // shake things up a bit
}
if gens_left > 0 {
child_generation(gens_left - 1, tx); // recurse
use std::os;
use std::env;
-use std::thread::Thread;
+use std::thread;
fn f(n: uint) {
let mut i = 0u;
while i < n {
- let _ = Thread::scoped(move|| g()).join();
+ let _ = thread::spawn(move|| g()).join();
i += 1u;
}
}
};
let n = args[1].parse().unwrap();
let mut i = 0u;
- while i < n { Thread::spawn(move|| f(n) ); i += 1u; }
+ while i < n { thread::spawn(move|| f(n) ); i += 1u; }
}
#![feature(box_syntax)]
-use std::thread::Thread;
+use std::thread;
fn borrow<F>(v: &isize, f: F) where F: FnOnce(&isize) {
f(v);
fn box_imm() {
let v = box 3;
let _w = &v;
- Thread::spawn(move|| {
+ thread::spawn(move|| {
println!("v={}", *v);
//~^ ERROR cannot move `v` into closure
});
fn box_imm_explicit() {
let v = box 3;
let _w = &v;
- Thread::spawn(move|| {
+ thread::spawn(move|| {
println!("v={}", *v);
//~^ ERROR cannot move
});
#![feature(box_syntax)]
-use std::thread::Thread;
+use std::thread;
fn borrow<T>(_: &T) { }
let p1 = &x1;
let x2 = box 2;
let p2 = &x2;
- Thread::spawn(move|| {
+ thread::spawn(move|| {
drop(x1); //~ ERROR cannot move `x1` into closure because it is borrowed
drop(x2); //~ ERROR cannot move `x2` into closure because it is borrowed
});
drop(x1);
let x2 = box 2;
drop(x2);
- Thread::spawn(move|| {
+ thread::spawn(move|| {
drop(x1); //~ ERROR capture of moved value: `x1`
drop(x2); //~ ERROR capture of moved value: `x2`
});
fn same_var_after_borrow() {
let x = box 1;
let p = &x;
- Thread::spawn(move|| {
+ thread::spawn(move|| {
drop(x); //~ ERROR cannot move `x` into closure because it is borrowed
drop(x); //~ ERROR use of moved value: `x`
});
fn same_var_after_move() {
let x = box 1;
drop(x);
- Thread::spawn(move|| {
+ thread::spawn(move|| {
drop(x); //~ ERROR capture of moved value: `x`
drop(x); //~ ERROR use of moved value: `x`
});
// except according to those terms.
use std::sync::mpsc::channel;
-use std::thread::Thread;
+use std::thread;
fn main() {
let (tx, rx) = channel();
- let _t = Thread::spawn(move|| -> () {
+ let _t = thread::spawn(move|| -> () {
loop {
let tx = tx;
//~^ ERROR: use of moved value: `tx`
// except according to those terms.
use std::{int, i8, i16, i32, i64};
-use std::thread::Thread;
+use std::thread;
fn main() {
- assert!(Thread::scoped(move|| int::MIN / -1).join().is_err());
+ assert!(thread::spawn(move|| int::MIN / -1).join().is_err());
//~^ ERROR attempted to divide with overflow in a constant expression
- assert!(Thread::scoped(move|| i8::MIN / -1).join().is_err());
+ assert!(thread::spawn(move|| i8::MIN / -1).join().is_err());
//~^ ERROR attempted to divide with overflow in a constant expression
- assert!(Thread::scoped(move|| i16::MIN / -1).join().is_err());
+ assert!(thread::spawn(move|| i16::MIN / -1).join().is_err());
//~^ ERROR attempted to divide with overflow in a constant expression
- assert!(Thread::scoped(move|| i32::MIN / -1).join().is_err());
+ assert!(thread::spawn(move|| i32::MIN / -1).join().is_err());
//~^ ERROR attempted to divide with overflow in a constant expression
- assert!(Thread::scoped(move|| i64::MIN / -1).join().is_err());
+ assert!(thread::spawn(move|| i64::MIN / -1).join().is_err());
//~^ ERROR attempted to divide with overflow in a constant expression
- assert!(Thread::scoped(move|| 1is / 0).join().is_err());
+ assert!(thread::spawn(move|| 1is / 0).join().is_err());
//~^ ERROR attempted to divide by zero in a constant expression
- assert!(Thread::scoped(move|| 1i8 / 0).join().is_err());
+ assert!(thread::spawn(move|| 1i8 / 0).join().is_err());
//~^ ERROR attempted to divide by zero in a constant expression
- assert!(Thread::scoped(move|| 1i16 / 0).join().is_err());
+ assert!(thread::spawn(move|| 1i16 / 0).join().is_err());
//~^ ERROR attempted to divide by zero in a constant expression
- assert!(Thread::scoped(move|| 1i32 / 0).join().is_err());
+ assert!(thread::spawn(move|| 1i32 / 0).join().is_err());
//~^ ERROR attempted to divide by zero in a constant expression
- assert!(Thread::scoped(move|| 1i64 / 0).join().is_err());
+ assert!(thread::spawn(move|| 1i64 / 0).join().is_err());
//~^ ERROR attempted to divide by zero in a constant expression
- assert!(Thread::scoped(move|| int::MIN % -1).join().is_err());
+ assert!(thread::spawn(move|| int::MIN % -1).join().is_err());
//~^ ERROR attempted remainder with overflow in a constant expression
- assert!(Thread::scoped(move|| i8::MIN % -1).join().is_err());
+ assert!(thread::spawn(move|| i8::MIN % -1).join().is_err());
//~^ ERROR attempted remainder with overflow in a constant expression
- assert!(Thread::scoped(move|| i16::MIN % -1).join().is_err());
+ assert!(thread::spawn(move|| i16::MIN % -1).join().is_err());
//~^ ERROR attempted remainder with overflow in a constant expression
- assert!(Thread::scoped(move|| i32::MIN % -1).join().is_err());
+ assert!(thread::spawn(move|| i32::MIN % -1).join().is_err());
//~^ ERROR attempted remainder with overflow in a constant expression
- assert!(Thread::scoped(move|| i64::MIN % -1).join().is_err());
+ assert!(thread::spawn(move|| i64::MIN % -1).join().is_err());
//~^ ERROR attempted remainder with overflow in a constant expression
- assert!(Thread::scoped(move|| 1is % 0).join().is_err());
+ assert!(thread::spawn(move|| 1is % 0).join().is_err());
//~^ ERROR attempted remainder with a divisor of zero in a constant expression
- assert!(Thread::scoped(move|| 1i8 % 0).join().is_err());
+ assert!(thread::spawn(move|| 1i8 % 0).join().is_err());
//~^ ERROR attempted remainder with a divisor of zero in a constant expression
- assert!(Thread::scoped(move|| 1i16 % 0).join().is_err());
+ assert!(thread::spawn(move|| 1i16 % 0).join().is_err());
//~^ ERROR attempted remainder with a divisor of zero in a constant expression
- assert!(Thread::scoped(move|| 1i32 % 0).join().is_err());
+ assert!(thread::spawn(move|| 1i32 % 0).join().is_err());
//~^ ERROR attempted remainder with a divisor of zero in a constant expression
- assert!(Thread::scoped(move|| 1i64 % 0).join().is_err());
+ assert!(thread::spawn(move|| 1i64 % 0).join().is_err());
//~^ ERROR attempted remainder with a divisor of zero in a constant expression
}
// #[stable] is not inherited
pub fn unmarked() {}
//~^ ERROR This node does not have a stability attribute
-}
\ No newline at end of file
+}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::thread::Thread;
+use std::thread;
fn main() {
let x = "Hello world!".to_string();
- Thread::spawn(move|| {
+ thread::spawn(move|| {
println!("{}", x);
});
println!("{}", x); //~ ERROR use of moved value
// error-pattern: use of moved value
use std::sync::Arc;
-use std::thread::Thread;
+use std::thread;
fn main() {
let v = vec!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
let arc_v = Arc::new(v);
- Thread::spawn(move|| {
+ thread::spawn(move|| {
assert_eq!((*arc_v)[3], 4);
});
// except according to those terms.
use std::sync::Arc;
-use std::thread::Thread;
+use std::thread;
fn main() {
let v = vec!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
let arc_v = Arc::new(v);
- Thread::spawn(move|| {
+ thread::spawn(move|| {
assert_eq!((*arc_v)[3], 4);
});
#![feature(unsafe_destructor)]
-use std::thread::Thread;
+use std::thread;
use std::rc::Rc;
#[derive(Debug)]
let x = foo(Port(Rc::new(())));
- Thread::spawn(move|| {
+ thread::spawn(move|| {
//~^ ERROR `core::marker::Send` is not implemented
let y = x;
println!("{:?}", y);
// error-pattern:thread '<unnamed>' panicked at 'test'
-use std::thread::Thread;
+use std::thread;
fn main() {
- let r: Result<int,_> = Thread::scoped(move|| {
+ let r: Result<int,_> = thread::spawn(move|| {
panic!("test");
1
}).join();
#[macro_use] extern crate log;
use std::os;
-use std::thread::Thread;
+use std::thread;
struct r {
x:int,
fn main() {
error!("whatever");
- let _t = Thread::spawn(move|| {
+ let _t = thread::spawn(move|| {
let _i = r(5);
});
panic!();
// error-pattern:Ensure that the child task runs by panicking
-use std::thread::Thread;
+use std::thread;
fn main() {
// the purpose of this test is to make sure that task::spawn()
// works when provided with a bare function:
- let r = Thread::scoped(startfn).join();
+ let r = thread::spawn(startfn).join();
if r.is_err() {
panic!()
}
#![feature(box_syntax)]
use std::sync::mpsc::{channel, Sender};
-use std::thread::Thread;
+use std::thread;
fn child(tx: &Sender<Box<uint>>, i: uint) {
tx.send(box i).unwrap();
let _t = (0u..n).map(|i| {
expected += i;
let tx = tx.clone();
- Thread::scoped(move|| {
+ thread::spawn(move|| {
child(&tx, i)
})
}).collect::<Vec<_>>();
// Make sure the destructor is run for unit-like structs.
use std::boxed::BoxAny;
-use std::thread::Thread;
+use std::thread;
struct Foo;
}
pub fn main() {
- let x = Thread::scoped(move|| {
+ let x = thread::spawn(move|| {
let _b = Foo;
}).join();
// except according to those terms.
use std::sync::mpsc::{channel, Sender};
-use std::thread::Thread;
+use std::thread;
struct complainer {
tx: Sender<bool>,
pub fn main() {
let (tx, rx) = channel();
- let _t = Thread::scoped(move|| f(tx.clone()));
+ let _t = thread::spawn(move|| f(tx.clone()));
println!("hiiiiiiiii");
assert!(rx.recv().unwrap());
}
#![allow(unknown_features)]
#![feature(box_syntax)]
-use std::thread::Thread;
+use std::thread;
fn f() {
let _a = box 0;
}
pub fn main() {
- let _t = Thread::scoped(f);
+ let _t = thread::spawn(f);
}
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use std::rand::{thread_rng, Rng, Rand};
-use std::thread::Thread;
+use std::thread;
const REPEATS: usize = 5;
const MAX_LEN: usize = 32;
let v = main.clone();
- let _ = Thread::scoped(move|| {
+ let _ = thread::spawn(move|| {
let mut v = v;
let mut panic_countdown = panic_countdown;
v.sort_by(|a, b| {
extern crate "weak-lang-items" as other;
-use std::thread::Thread;
+use std::thread;
fn main() {
- let _ = Thread::scoped(move|| {
+ let _ = thread::spawn(move|| {
other::foo()
});
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::thread::Thread;
+use std::thread;
pub fn main() {
- let mut result = Thread::scoped(child);
+ let mut result = thread::spawn(child);
println!("1");
- Thread::yield_now();
+ thread::yield_now();
println!("2");
- Thread::yield_now();
+ thread::yield_now();
println!("3");
result.join();
}
fn child() {
- println!("4"); Thread::yield_now(); println!("5"); Thread::yield_now(); println!("6");
+ println!("4"); thread::yield_now(); println!("5"); thread::yield_now(); println!("6");
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::thread::Thread;
+use std::thread;
pub fn main() {
- let mut result = Thread::scoped(child);
+ let mut result = thread::spawn(child);
println!("1");
- Thread::yield_now();
+ thread::yield_now();
result.join();
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::thread::Thread;
+use std::thread;
pub fn main() {
let mut i: int = 0;
- while i < 100 { i = i + 1; println!("{}", i); Thread::yield_now(); }
+ while i < 100 { i = i + 1; println!("{}", i); thread::yield_now(); }
}