From efd2a1780b2ee1909e84df0c3b398adb024ee375 Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Mon, 16 Feb 2015 16:33:55 -0800 Subject: Deprecate std::sync::TaskPool Rather than stabilize on the current API, we're going to punt this concern to crates.io, to allow for faster iteration. If you need this functionality, you might look at https://github.com/carllerche/syncbox [breaking-change] --- src/libstd/sync/task_pool.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/libstd/sync') diff --git a/src/libstd/sync/task_pool.rs b/src/libstd/sync/task_pool.rs index 684a46fd6ff..2bc51e340c0 100644 --- a/src/libstd/sync/task_pool.rs +++ b/src/libstd/sync/task_pool.rs @@ -10,11 +10,11 @@ //! Abstraction of a thread pool for basic parallelism. -#![unstable(feature = "std_misc", - reason = "the semantics of a failing task and whether a thread is \ - re-attached to a thread pool are somewhat unclear, and the \ - utility of this type in `std::sync` is questionable with \ - respect to the jobs of other primitives")] +#![deprecated(since = "1.0.0", + reason = "This kind of API needs some time to bake in \ + crates.io. Consider trying \ + https://github.com/carllerche/syncbox")] +#![unstable(feature = "std_misc")] use core::prelude::*; -- cgit 1.4.1-3-g733a5 From 64fe93e49dc0c6a552c5f08507064f2ce12800ca Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 20 Feb 2015 12:00:26 -0800 Subject: std: Tidy up some `unsafe impl`s for `sync` This commit removes many unnecessary `unsafe impl` blocks as well as pushing the needed implementations to the lowest level possible. I noticed that the bounds for `RwLock` are a little off when reviewing #22574 and wanted to ensure that we had our story straight on these implementations. --- src/libstd/sync/condvar.rs | 6 ------ src/libstd/sync/mutex.rs | 2 -- src/libstd/sync/once.rs | 7 ++----- src/libstd/sync/poison.rs | 6 ++++++ src/libstd/sync/rwlock.rs | 3 --- src/libstd/sys/unix/condvar.rs | 6 +++++- src/libstd/sys/unix/mutex.rs | 4 +++- src/libstd/sys/unix/rwlock.rs | 5 +++++ src/libstd/sys/windows/condvar.rs | 5 +++++ src/libstd/sys/windows/mutex.rs | 17 +++++++++------- src/libstd/sys/windows/rwlock.rs | 5 +++++ src/test/run-pass/std-sync-right-kind-impls.rs | 27 ++++++++++++++++++++++++++ 12 files changed, 68 insertions(+), 25 deletions(-) create mode 100644 src/test/run-pass/std-sync-right-kind-impls.rs (limited to 'src/libstd/sync') diff --git a/src/libstd/sync/condvar.rs b/src/libstd/sync/condvar.rs index 52561d482c3..fa45f72b3a1 100644 --- a/src/libstd/sync/condvar.rs +++ b/src/libstd/sync/condvar.rs @@ -61,9 +61,6 @@ use sync::{mutex, MutexGuard, PoisonError}; #[stable(feature = "rust1", since = "1.0.0")] pub struct Condvar { inner: Box } -unsafe impl Send for Condvar {} -unsafe impl Sync for Condvar {} - /// Statically allocated condition variables. /// /// This structure is identical to `Condvar` except that it is suitable for use @@ -83,9 +80,6 @@ pub struct StaticCondvar { mutex: AtomicUsize, } -unsafe impl Send for StaticCondvar {} -unsafe impl Sync for StaticCondvar {} - /// Constant initializer for a statically allocated condition variable. #[unstable(feature = "std_misc", reason = "may be merged with Condvar in the future")] diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index e77c4d2e5eb..a4129e315ff 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -152,8 +152,6 @@ pub struct StaticMutex { poison: poison::Flag, } -unsafe impl Sync for StaticMutex {} - /// An RAII implementation of a "scoped lock" of a mutex. When this structure is /// dropped (falls out of scope), the lock will be unlocked. /// diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index 97f985e21e8..d2054a1e819 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -13,10 +13,9 @@ //! This primitive is meant to be used to run one-time initialization. An //! example use case would be for initializing an FFI library. +use prelude::v1::*; + use isize; -use marker::Sync; -use mem::drop; -use ops::FnOnce; use sync::atomic::{AtomicIsize, Ordering, ATOMIC_ISIZE_INIT}; use sync::{StaticMutex, MUTEX_INIT}; @@ -43,8 +42,6 @@ pub struct Once { lock_cnt: AtomicIsize, } -unsafe impl Sync for Once {} - /// Initialization value for static `Once` values. #[stable(feature = "rust1", since = "1.0.0")] pub const ONCE_INIT: Once = Once { diff --git a/src/libstd/sync/poison.rs b/src/libstd/sync/poison.rs index 32c8150ba40..2587ff5238e 100644 --- a/src/libstd/sync/poison.rs +++ b/src/libstd/sync/poison.rs @@ -16,6 +16,12 @@ use fmt; use thread; pub struct Flag { failed: UnsafeCell } + +// This flag is only ever accessed with a lock previously held. Note that this +// a totally private structure. +unsafe impl Send for Flag {} +unsafe impl Sync for Flag {} + pub const FLAG_INIT: Flag = Flag { failed: UnsafeCell { value: false } }; impl Flag { diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index cd833b17867..c32fd88ab24 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -97,9 +97,6 @@ pub struct StaticRwLock { poison: poison::Flag, } -unsafe impl Send for StaticRwLock {} -unsafe impl Sync for StaticRwLock {} - /// Constant initialization for a statically-initialized rwlock. #[unstable(feature = "std_misc", reason = "may be merged with RwLock in the future")] diff --git a/src/libstd/sys/unix/condvar.rs b/src/libstd/sys/unix/condvar.rs index 3bc41473152..90dfebc4c45 100644 --- a/src/libstd/sys/unix/condvar.rs +++ b/src/libstd/sys/unix/condvar.rs @@ -8,10 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use prelude::v1::*; + use cell::UnsafeCell; use libc; use ptr; -use std::option::Option::{Some, None}; use sys::mutex::{self, Mutex}; use sys::time; use sys::sync as ffi; @@ -20,6 +21,9 @@ use num::{Int, NumCast}; pub struct Condvar { inner: UnsafeCell } +unsafe impl Send for Condvar {} +unsafe impl Sync for Condvar {} + pub const CONDVAR_INIT: Condvar = Condvar { inner: UnsafeCell { value: ffi::PTHREAD_COND_INITIALIZER }, }; diff --git a/src/libstd/sys/unix/mutex.rs b/src/libstd/sys/unix/mutex.rs index 9e1527aef20..f87c0339533 100644 --- a/src/libstd/sys/unix/mutex.rs +++ b/src/libstd/sys/unix/mutex.rs @@ -8,8 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use prelude::v1::*; + use cell::UnsafeCell; -use marker::Sync; use sys::sync as ffi; use sys_common::mutex; @@ -24,6 +25,7 @@ pub const MUTEX_INIT: Mutex = Mutex { inner: UnsafeCell { value: ffi::PTHREAD_MUTEX_INITIALIZER }, }; +unsafe impl Send for Mutex {} unsafe impl Sync for Mutex {} impl Mutex { diff --git a/src/libstd/sys/unix/rwlock.rs b/src/libstd/sys/unix/rwlock.rs index 54523e0076d..b857f4ab75f 100644 --- a/src/libstd/sys/unix/rwlock.rs +++ b/src/libstd/sys/unix/rwlock.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use prelude::v1::*; + use cell::UnsafeCell; use sys::sync as ffi; @@ -17,6 +19,9 @@ pub const RWLOCK_INIT: RWLock = RWLock { inner: UnsafeCell { value: ffi::PTHREAD_RWLOCK_INITIALIZER }, }; +unsafe impl Send for RWLock {} +unsafe impl Sync for RWLock {} + impl RWLock { #[inline] pub unsafe fn new() -> RWLock { diff --git a/src/libstd/sys/windows/condvar.rs b/src/libstd/sys/windows/condvar.rs index db8038006fd..071637e3a93 100644 --- a/src/libstd/sys/windows/condvar.rs +++ b/src/libstd/sys/windows/condvar.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use prelude::v1::*; + use cell::UnsafeCell; use libc::{self, DWORD}; use os; @@ -17,6 +19,9 @@ use time::Duration; pub struct Condvar { inner: UnsafeCell } +unsafe impl Send for Condvar {} +unsafe impl Sync for Condvar {} + pub const CONDVAR_INIT: Condvar = Condvar { inner: UnsafeCell { value: ffi::CONDITION_VARIABLE_INIT } }; diff --git a/src/libstd/sys/windows/mutex.rs b/src/libstd/sys/windows/mutex.rs index 75495efc7cb..0847f3b52bf 100644 --- a/src/libstd/sys/windows/mutex.rs +++ b/src/libstd/sys/windows/mutex.rs @@ -8,7 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use marker::Sync; +use prelude::v1::*; + use cell::UnsafeCell; use sys::sync as ffi; @@ -18,6 +19,7 @@ pub const MUTEX_INIT: Mutex = Mutex { inner: UnsafeCell { value: ffi::SRWLOCK_INIT } }; +unsafe impl Send for Mutex {} unsafe impl Sync for Mutex {} #[inline] @@ -27,14 +29,15 @@ pub unsafe fn raw(m: &Mutex) -> ffi::PSRWLOCK { // So you might be asking why we're using SRWLock instead of CriticalSection? // -// 1. SRWLock is several times faster than CriticalSection according to benchmarks performed on both -// Windows 8 and Windows 7. +// 1. SRWLock is several times faster than CriticalSection according to +// benchmarks performed on both Windows 8 and Windows 7. // -// 2. CriticalSection allows recursive locking while SRWLock deadlocks. The Unix implementation -// deadlocks so consistency is preferred. See #19962 for more details. +// 2. CriticalSection allows recursive locking while SRWLock deadlocks. The Unix +// implementation deadlocks so consistency is preferred. See #19962 for more +// details. // -// 3. While CriticalSection is fair and SRWLock is not, the current Rust policy is there there are -// no guarantees of fairness. +// 3. While CriticalSection is fair and SRWLock is not, the current Rust policy +// is there there are no guarantees of fairness. impl Mutex { #[inline] diff --git a/src/libstd/sys/windows/rwlock.rs b/src/libstd/sys/windows/rwlock.rs index 76fe352ed77..009605535a0 100644 --- a/src/libstd/sys/windows/rwlock.rs +++ b/src/libstd/sys/windows/rwlock.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use prelude::v1::*; + use cell::UnsafeCell; use sys::sync as ffi; @@ -17,6 +19,9 @@ pub const RWLOCK_INIT: RWLock = RWLock { inner: UnsafeCell { value: ffi::SRWLOCK_INIT } }; +unsafe impl Send for RWLock {} +unsafe impl Sync for RWLock {} + impl RWLock { #[inline] pub unsafe fn read(&self) { diff --git a/src/test/run-pass/std-sync-right-kind-impls.rs b/src/test/run-pass/std-sync-right-kind-impls.rs new file mode 100644 index 00000000000..d2d72ed1661 --- /dev/null +++ b/src/test/run-pass/std-sync-right-kind-impls.rs @@ -0,0 +1,27 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::sync; + +fn assert_both() {} + +fn main() { + assert_both::(); + assert_both::(); + assert_both::(); + assert_both::>(); + assert_both::(); + assert_both::>(); + assert_both::(); + assert_both::(); + assert_both::>(); + assert_both::>(); + assert_both::(); +} -- cgit 1.4.1-3-g733a5 From 27f8708ba4aac3f4f2d3074b7b4a451774b1a813 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 24 Feb 2015 14:24:15 -0800 Subject: std: Recomend threadpool on crates.io for TaskPool --- src/libstd/sync/task_pool.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libstd/sync') diff --git a/src/libstd/sync/task_pool.rs b/src/libstd/sync/task_pool.rs index 2bc51e340c0..83e4c6c2e3b 100644 --- a/src/libstd/sync/task_pool.rs +++ b/src/libstd/sync/task_pool.rs @@ -12,8 +12,8 @@ #![deprecated(since = "1.0.0", reason = "This kind of API needs some time to bake in \ - crates.io. Consider trying \ - https://github.com/carllerche/syncbox")] + crates.io. This functionality is available through \ + https://crates.io/crates/threadpool")] #![unstable(feature = "std_misc")] use core::prelude::*; -- cgit 1.4.1-3-g733a5 From f8e4fcb38c2ab0b5180c8fff35ad0454eb0667d7 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Wed, 25 Feb 2015 11:45:06 +0530 Subject: allow(deprecated) for TaskPool (fixup #22783) --- src/libstd/sync/mod.rs | 1 + src/libstd/sync/task_pool.rs | 2 ++ 2 files changed, 3 insertions(+) (limited to 'src/libstd/sync') diff --git a/src/libstd/sync/mod.rs b/src/libstd/sync/mod.rs index f3b721438d8..68137601c40 100644 --- a/src/libstd/sync/mod.rs +++ b/src/libstd/sync/mod.rs @@ -31,6 +31,7 @@ pub use self::barrier::{Barrier, BarrierWaitResult}; pub use self::poison::{PoisonError, TryLockError, TryLockResult, LockResult}; pub use self::future::Future; +#[allow(deprecated)] pub use self::task_pool::TaskPool; pub mod mpsc; diff --git a/src/libstd/sync/task_pool.rs b/src/libstd/sync/task_pool.rs index e01f8145283..efb6689e785 100644 --- a/src/libstd/sync/task_pool.rs +++ b/src/libstd/sync/task_pool.rs @@ -16,6 +16,8 @@ https://crates.io/crates/threadpool")] #![unstable(feature = "std_misc")] +#![allow(deprecated)] + use core::prelude::*; use sync::{Arc, Mutex}; -- cgit 1.4.1-3-g733a5