diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-01-02 08:54:58 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-01-02 08:54:58 -0800 |
| commit | 5696ea58946f077f815dc5f74b883cf948c7e1ea (patch) | |
| tree | 0ecc90224cb9e0d68bf276ebd447d61a6bd72a59 /src/libstd/sync/mutex.rs | |
| parent | 71b46b18a274edc7f7fb60b490e5ebbb9c911462 (diff) | |
| parent | 76e3bc23388e268438e4318b0580149619a9d1ac (diff) | |
| download | rust-5696ea58946f077f815dc5f74b883cf948c7e1ea.tar.gz rust-5696ea58946f077f815dc5f74b883cf948c7e1ea.zip | |
rollup merge of #20157: alexcrichton/issue-20068
Diffstat (limited to 'src/libstd/sync/mutex.rs')
| -rw-r--r-- | src/libstd/sync/mutex.rs | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index 52004bb4a8f..98425f26c1a 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -8,10 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use prelude::*; +use prelude::v1::*; use cell::UnsafeCell; use kinds::marker; +use ops::{Deref, DerefMut}; use sync::poison::{mod, TryLockError, TryLockResult, LockResult}; use sys_common::mutex as sys; @@ -47,6 +48,8 @@ use sys_common::mutex as sys; /// ```rust /// use std::sync::{Arc, Mutex}; /// use std::thread::Thread; +/// use std::comm::channel; +/// /// const N: uint = 10; /// /// // Spawn a few threads to increment a shared variable (non-atomically), and @@ -320,10 +323,11 @@ pub fn guard_poison<'a, T>(guard: &MutexGuard<'a, T>) -> &'a poison::Flag { #[cfg(test)] mod test { - use prelude::*; + use prelude::v1::*; - use thread::Thread; + use comm::channel; use sync::{Arc, Mutex, StaticMutex, MUTEX_INIT, Condvar}; + use thread::Thread; struct Packet<T>(Arc<(Mutex<T>, Condvar)>); @@ -366,9 +370,9 @@ mod test { let (tx, rx) = channel(); for _ in range(0, K) { let tx2 = tx.clone(); - spawn(move|| { inc(); tx2.send(()); }); + Thread::spawn(move|| { inc(); tx2.send(()); }).detach(); let tx2 = tx.clone(); - spawn(move|| { inc(); tx2.send(()); }); + Thread::spawn(move|| { inc(); tx2.send(()); }).detach(); } drop(tx); @@ -392,7 +396,7 @@ mod test { let packet = Packet(Arc::new((Mutex::new(false), Condvar::new()))); let packet2 = Packet(packet.0.clone()); let (tx, rx) = channel(); - spawn(move|| { + let _t = Thread::spawn(move|| { // wait until parent gets in rx.recv(); let &(ref lock, ref cvar) = &*packet2.0; @@ -416,7 +420,7 @@ mod test { let packet2 = Packet(packet.0.clone()); let (tx, rx) = channel(); - spawn(move|| { + let _t = Thread::spawn(move || -> () { rx.recv(); let &(ref lock, ref cvar) = &*packet2.0; let _g = lock.lock().unwrap(); @@ -457,9 +461,9 @@ mod test { let arc = Arc::new(Mutex::new(1i)); let arc2 = Arc::new(Mutex::new(arc)); let (tx, rx) = channel(); - spawn(move|| { + let _t = Thread::spawn(move|| { let lock = arc2.lock().unwrap(); - let lock2 = lock.deref().lock().unwrap(); + let lock2 = lock.lock().unwrap(); assert_eq!(*lock2, 1); tx.send(()); }); |
