about summary refs log tree commit diff
path: root/src/libstd/sync
AgeCommit message (Collapse)AuthorLines
2015-01-06rollup merge of #20615: aturon/stab-2-threadAlex Crichton-57/+57
This commit takes a first pass at stabilizing `std::thread`: * It removes the `detach` method in favor of two constructors -- `spawn` for detached threads, `scoped` for "scoped" (i.e., must-join) threads. This addresses some of the surprise/frustrating debug sessions with the previous API, in which `spawn` produced a guard that on destruction joined the thread (unless `detach` was called). The reason to have the division in part is that `Send` will soon not imply `'static`, which means that `scoped` thread creation can take a closure over *shared stack data* of the parent thread. On the other hand, this means that the parent must not pop the relevant stack frames while the child thread is running. The `JoinGuard` is used to prevent this from happening by joining on drop (if you have not already explicitly `join`ed.) The APIs around `scoped` are future-proofed for the `Send` changes by taking an additional lifetime parameter. With the current definition of `Send`, this is forced to be `'static`, but when `Send` changes these APIs will gain their full flexibility immediately. Threads that are `spawn`ed, on the other hand, are detached from the start and do not yield an RAII guard. The hope is that, by making `scoped` an explicit opt-in with a very suggestive name, it will be drastically less likely to be caught by a surprising deadlock due to an implicit join at the end of a scope. * The module itself is marked stable. * Existing methods other than `spawn` and `scoped` are marked stable. The migration path is: ```rust Thread::spawn(f).detached() ``` becomes ```rust Thread::spawn(f) ``` while ```rust let res = Thread::spawn(f); res.join() ``` becomes ```rust let res = Thread::scoped(f); res.join() ``` [breaking-change]
2015-01-06rollup merge of #20607: nrc/kindsAlex Crichton-7/+7
Conflicts: src/libcore/array.rs src/libcore/cell.rs src/libcore/prelude.rs src/libstd/path/posix.rs src/libstd/prelude/v1.rs src/test/compile-fail/dst-sized-trait-param.rs
2015-01-07markers -> markerNick Cameron-17/+17
2015-01-06Fallout from stabilizationAaron Turon-57/+57
2015-01-07Replace full slice notation with index callsNick Cameron-1/+2
2015-01-07Change `std::kinds` to `std::markers`; flatten `std::kinds::marker`Nick Cameron-17/+17
[breaking-change]
2015-01-05Revert "Remove i suffix in docs"Alex Crichton-693/+722
This reverts commit f031671c6ea79391eeb3e1ad8f06fe0e436103fb. Conflicts: src/libcollections/slice.rs src/libcore/iter.rs src/libstd/sync/mpsc/mod.rs src/libstd/sync/rwlock.rs
2015-01-05rollup merge of #20565: alexcrichton/missing-stabilityAlex Crichton-7/+5
Conflicts: src/libstd/sync/mpsc/mod.rs
2015-01-05rollup merge of #20560: aturon/stab-2-iter-ops-sliceAlex Crichton-3/+21
Conflicts: src/libcollections/slice.rs src/libcore/iter.rs src/libstd/sync/mpsc/mod.rs src/libstd/sync/rwlock.rs
2015-01-05rollup merge of #20519: ville-h/rwlock-renameAlex Crichton-84/+84
Conflicts: src/libstd/sync/rwlock.rs
2015-01-05Remove i suffix in docsSteve Klabnik-726/+696
2015-01-05Stabilization of impls and fallout from stabilizationAaron Turon-1/+17
2015-01-04std: Fix missing stability in syncAlex Crichton-5/+4
* The `sync` module is stable * The `sync::mpsc` module is stable * The `Sender::send` method is stable. * The `Once::doit` method is now removed. * Deprecated atomic initializers are removed. * Renamed atomic initializers are now stable.
2015-01-04Merge pull request #20510 from tshepang/patch-6bors-1/+1
doc: remove incomplete sentence Reviewed-by: steveklabnik, steveklabnik
2015-01-04fix comment referencing RwLockville-h-1/+1
2015-01-04fix code referencing RwLockWriteGuardville-h-9/+9
2015-01-04rename std::sync::RWLockWriteGuard to RwLockWriteGuardville-h-7/+7
2015-01-04fix code referencing RwLockReadGuardville-h-9/+9
2015-01-04rename std::sync::RWLockReadGuard to RwLockReadGuardville-h-6/+6
2015-01-04fix code and comments referencing RW_LOCK_INITville-h-7/+7
2015-01-03Remove deprecated functionalityAlex Crichton-375/+147
This removes a large array of deprecated functionality, regardless of how recently it was deprecated. The purpose of this commit is to clean out the standard libraries and compiler for the upcoming alpha release. Some notable compiler changes were to enable warnings for all now-deprecated command line arguments (previously the deprecated versions were silently accepted) as well as removing deriving(Zero) entirely (the trait was removed). The distribution no longer contains the libtime or libregex_macros crates. Both of these have been deprecated for some time and are available externally.
2015-01-04rename std::sync::RWLOCK_INIT to RW_LOCK_INITville-h-1/+1
2015-01-04fix code and comments referencing StaticRwLockville-h-12/+12
2015-01-04doc: remove incomplete sentenceTshepang Lekhonkhobe-1/+1
2015-01-03sed -i -s 's/#\[deriving(/#\[derive(/g' **/*.rsJorge Aparicio-7/+7
2015-01-03sed -i -s 's/\bmod,/self,/g' **/*.rsJorge Aparicio-12/+12
2015-01-04rename std::sync::StaticRWLock to StaticRwLockville-h-4/+4
2015-01-04fix code and comments referencing RwLockville-h-32/+32
2015-01-03rename std::sync::RWLock to RwLockville-h-7/+7
2015-01-03std: fix falloutJorge Aparicio-2/+6
2015-01-02rollup merge of #20410: japaric/assoc-typesAlex Crichton-5/+11
Conflicts: src/liballoc/lib.rs src/libcollections/lib.rs src/libcollections/slice.rs src/libcore/ops.rs src/libcore/prelude.rs src/libcore/ptr.rs src/librustc/middle/traits/project.rs src/libstd/c_str.rs src/libstd/io/mem.rs src/libstd/io/mod.rs src/libstd/lib.rs src/libstd/path/posix.rs src/libstd/path/windows.rs src/libstd/prelude.rs src/libstd/rt/exclusive.rs src/libsyntax/lib.rs src/test/compile-fail/issue-18566.rs src/test/run-pass/deref-mut-on-ref.rs src/test/run-pass/deref-on-ref.rs src/test/run-pass/dst-deref-mut.rs src/test/run-pass/dst-deref.rs src/test/run-pass/fixup-deref-mut.rs src/test/run-pass/issue-13264.rs src/test/run-pass/overloaded-autoderef-indexing.rs
2015-01-02Rollup test fixes and rebase conflictsAlex Crichton-4/+3
2015-01-02core: use assoc types in `Deref[Mut]`Jorge Aparicio-5/+11
2015-01-02rollup merge of #20315: alexcrichton/std-syncAlex Crichton-36/+81
Conflicts: src/libstd/rt/exclusive.rs src/libstd/sync/barrier.rs src/libstd/sys/unix/pipe.rs src/test/bench/shootout-binarytrees.rs src/test/bench/shootout-fannkuch-redux.rs
2015-01-02rollup merge of #20273: alexcrichton/second-pass-commAlex Crichton-57/+5348
Conflicts: src/doc/guide.md src/libcollections/bit.rs src/libcollections/btree/node.rs src/libcollections/slice.rs src/libcore/ops.rs src/libcore/prelude.rs src/librand/rand_impls.rs src/librustc/middle/check_match.rs src/librustc/middle/infer/region_inference/mod.rs src/librustc_driver/lib.rs src/librustdoc/test.rs src/libstd/bitflags.rs src/libstd/io/comm_adapters.rs src/libstd/io/mem.rs src/libstd/io/mod.rs src/libstd/io/net/pipe.rs src/libstd/io/net/tcp.rs src/libstd/io/net/udp.rs src/libstd/io/pipe.rs src/libstd/io/process.rs src/libstd/io/stdio.rs src/libstd/io/timer.rs src/libstd/io/util.rs src/libstd/macros.rs src/libstd/os.rs src/libstd/path/posix.rs src/libstd/path/windows.rs src/libstd/prelude/v1.rs src/libstd/rand/mod.rs src/libstd/rand/os.rs src/libstd/sync/barrier.rs src/libstd/sync/condvar.rs src/libstd/sync/future.rs src/libstd/sync/mpsc/mod.rs src/libstd/sync/mpsc/mpsc_queue.rs src/libstd/sync/mpsc/select.rs src/libstd/sync/mpsc/spsc_queue.rs src/libstd/sync/mutex.rs src/libstd/sync/once.rs src/libstd/sync/rwlock.rs src/libstd/sync/semaphore.rs src/libstd/sync/task_pool.rs src/libstd/sys/common/helper_thread.rs src/libstd/sys/unix/process.rs src/libstd/sys/unix/timer.rs src/libstd/sys/windows/c.rs src/libstd/sys/windows/timer.rs src/libstd/sys/windows/tty.rs src/libstd/thread.rs src/libstd/thread_local/mod.rs src/libstd/thread_local/scoped.rs src/libtest/lib.rs src/test/auxiliary/cci_capture_clause.rs src/test/bench/shootout-reverse-complement.rs src/test/bench/shootout-spectralnorm.rs src/test/compile-fail/array-old-syntax-2.rs src/test/compile-fail/bind-by-move-no-guards.rs src/test/compile-fail/builtin-superkinds-self-type.rs src/test/compile-fail/comm-not-freeze-receiver.rs src/test/compile-fail/comm-not-freeze.rs src/test/compile-fail/issue-12041.rs src/test/compile-fail/unsendable-class.rs src/test/run-pass/builtin-superkinds-capabilities-transitive.rs src/test/run-pass/builtin-superkinds-capabilities-xc.rs src/test/run-pass/builtin-superkinds-capabilities.rs src/test/run-pass/builtin-superkinds-self-type.rs src/test/run-pass/capturing-logging.rs src/test/run-pass/closure-bounds-can-capture-chan.rs src/test/run-pass/comm.rs src/test/run-pass/core-run-destroy.rs src/test/run-pass/drop-trait-enum.rs src/test/run-pass/hashmap-memory.rs src/test/run-pass/issue-13494.rs src/test/run-pass/issue-3609.rs src/test/run-pass/issue-4446.rs src/test/run-pass/issue-4448.rs src/test/run-pass/issue-8827.rs src/test/run-pass/issue-9396.rs src/test/run-pass/ivec-tag.rs src/test/run-pass/rust-log-filter.rs src/test/run-pass/send-resource.rs src/test/run-pass/send-type-inference.rs src/test/run-pass/sendable-class.rs src/test/run-pass/spawn-types.rs src/test/run-pass/task-comm-0.rs src/test/run-pass/task-comm-10.rs src/test/run-pass/task-comm-11.rs src/test/run-pass/task-comm-13.rs src/test/run-pass/task-comm-14.rs src/test/run-pass/task-comm-15.rs src/test/run-pass/task-comm-16.rs src/test/run-pass/task-comm-3.rs src/test/run-pass/task-comm-4.rs src/test/run-pass/task-comm-5.rs src/test/run-pass/task-comm-6.rs src/test/run-pass/task-comm-7.rs src/test/run-pass/task-comm-9.rs src/test/run-pass/task-comm-chan-nil.rs src/test/run-pass/task-spawn-move-and-copy.rs src/test/run-pass/task-stderr.rs src/test/run-pass/tcp-accept-stress.rs src/test/run-pass/tcp-connect-timeouts.rs src/test/run-pass/tempfile.rs src/test/run-pass/trait-bounds-in-arc.rs src/test/run-pass/trivial-message.rs src/test/run-pass/unique-send-2.rs src/test/run-pass/unique-send.rs src/test/run-pass/unwind-resource.rs
2015-01-02std: Stabilize the prelude moduleAlex Crichton-45/+59
This commit is an implementation of [RFC 503][rfc] which is a stabilization story for the prelude. Most of the RFC was directly applied, removing reexports. Some reexports are kept around, however: * `range` remains until range syntax has landed to reduce churn. * `Path` and `GenericPath` remain until path reform lands. This is done to prevent many imports of `GenericPath` which will soon be removed. * All `io` traits remain until I/O reform lands so imports can be rewritten all at once to `std::io::prelude::*`. This is a breaking change because many prelude reexports have been removed, and the RFC can be consulted for the exact list of removed reexports, as well as to find the locations of where to import them. [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0503-prelude-stabilization.md [breaking-change] Closes #20068
2015-01-01std: Second pass stabilization of syncAlex Crichton-35/+80
This pass performs a second pass of stabilization through the `std::sync` module, avoiding modules/types that are being handled in other PRs (e.g. mutexes, rwlocks, condvars, and channels). The following items are now stable * `sync::atomic` * `sync::atomic::ATOMIC_BOOL_INIT` (was `INIT_ATOMIC_BOOL`) * `sync::atomic::ATOMIC_INT_INIT` (was `INIT_ATOMIC_INT`) * `sync::atomic::ATOMIC_UINT_INIT` (was `INIT_ATOMIC_UINT`) * `sync::Once` * `sync::ONCE_INIT` * `sync::Once::call_once` (was `doit`) * C == `pthread_once(..)` * Boost == `call_once(..)` * Windows == `InitOnceExecuteOnce` * `sync::Barrier` * `sync::Barrier::new` * `sync::Barrier::wait` (now returns a `bool`) * `sync::Semaphore::new` * `sync::Semaphore::acquire` * `sync::Semaphore::release` The following items remain unstable * `sync::SemaphoreGuard` * `sync::Semaphore::access` - it's unclear how this relates to the poisoning story of mutexes. * `sync::TaskPool` - 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 `sync` is question with respect to the jobs of other primitives. This type will likely become stable or move out of the standard library over time. * `sync::Future` - futures as-is have yet to be deeply re-evaluated with the recent core changes to Rust's synchronization story, and will likely become stable in the future but are unstable until that time comes. [breaking-change]
2014-12-30Remove core::atomic::Ordering::* public reexportCorey Farwell-1/+1
Part of #19253 [breaking-change]
2014-12-29Test fixes and rebase conflictsAlex Crichton-8/+12
2014-12-29rollup merge of #20289: nick29581/shadowingAlex Crichton-1/+1
r? eddyb
2014-12-29rollup merge of #20264: nagisa/threadrngAlex Crichton-1/+1
Since runtime is removed, rust has no tasks anymore and everything is moving from being task-* to thread-*. Let’s rename TaskRng as well! This is a breaking change. If a breaking change for consistency is not desired, feel free to close.
2014-12-29rollup merge of #20248: steveklabnik/gh20038Alex Crichton-16/+16
A part of #20038 This is just the beginning of what needs to be done, but it's some of it. /cc @aturon
2014-12-29std: Stabilization pass for mutex/rwlock/condvarAlex Crichton-227/+149
This commit performs a stabilization pass over the sync::{mutex, rwlock, condvar} modules, marking the following items as stable: * Mutex * Mutex::new * Mutex::lock * Mutex::try_lock * MutexGuard * RWLock * RWLock::new * RWLock::read * RWLock::try_read * RWLock::write * RWLock::try_write * RWLockReadGuard * RWLockWriteGuard * Condvar * Condvar::new * Condvar::wait * Condvar::notify_one * Condvar::notify_all * PoisonError * TryLockError * TryLockError::Poisoned * TryLockError::WouldBlock * LockResult * TryLockResult The following items remain unstable to explore future possibilities of unifying the static/non-static variants of the types: * StaticMutex * StaticMutex::new * StaticMutex::lock * StaticMutex::try_lock * StaticMutex::desroy * StaticRWLock * StaticRWLock::new * StaticRWLock::read * StaticRWLock::try_read * StaticRWLock::write * StaticRWLock::try_write * StaticRWLock::destroy The following items were removed in favor of `Guard<'static, ()>` instead. * StaticMutexGuard * StaticRWLockReadGuard * StaticRWLockWriteGuard
2014-12-29std: Second pass stabilization for `comm`Alex Crichton-57/+5348
This commit is a second pass stabilization for the `std::comm` module, performing the following actions: * The entire `std::comm` module was moved under `std::sync::mpsc`. This movement reflects that channels are just yet another synchronization primitive, and they don't necessarily deserve a special place outside of the other concurrency primitives that the standard library offers. * The `send` and `recv` methods have all been removed. * The `send_opt` and `recv_opt` methods have been renamed to `send` and `recv`. This means that all send/receive operations return a `Result` now indicating whether the operation was successful or not. * The error type of `send` is now a `SendError` to implement a custom error message and allow for `unwrap()`. The error type contains an `into_inner` method to extract the value. * The error type of `recv` is now `RecvError` for the same reasons as `send`. * The `TryRecvError` and `TrySendError` types have had public reexports removed of their variants and the variant names have been tweaked with enum namespacing rules. * The `Messages` iterator is renamed to `Iter` This functionality is now all `#[stable]`: * `Sender` * `SyncSender` * `Receiver` * `std::sync::mpsc` * `channel` * `sync_channel` * `Iter` * `Sender::send` * `Sender::clone` * `SyncSender::send` * `SyncSender::try_send` * `SyncSender::clone` * `Receiver::recv` * `Receiver::try_recv` * `Receiver::iter` * `SendError` * `RecvError` * `TrySendError::{mod, Full, Disconnected}` * `TryRecvError::{mod, Empty, Disconnected}` * `SendError::into_inner` * `TrySendError::into_inner` This is a breaking change due to the modification of where this module is located, as well as the changing of the semantics of `send` and `recv`. Most programs just need to rename imports of `std::comm` to `std::sync::mpsc` and add calls to `unwrap` after a send or a receive operation. [breaking-change]
2014-12-29std: Return Result from RWLock/Mutex methodsAlex Crichton-282/+508
All of the current std::sync primitives have poisoning enable which means that when a task fails inside of a write-access lock then all future attempts to acquire the lock will fail. This strategy ensures that stale data whose invariants are possibly not upheld are never viewed by other tasks to help propagate unexpected panics (bugs in a program) among tasks. Currently there is no way to test whether a mutex or rwlock is poisoned. One method would be to duplicate all the methods with a sister foo_catch function, for example. This pattern is, however, against our [error guidelines][errors]. As a result, this commit exposes the fact that a task has failed internally through the return value of a `Result`. [errors]: https://github.com/rust-lang/rfcs/blob/master/text/0236-error-conventions.md#do-not-provide-both-result-and-fail-variants All methods now return a `LockResult<T>` or a `TryLockResult<T>` which communicates whether the lock was poisoned or not. In a `LockResult`, both the `Ok` and `Err` variants contains the `MutexGuard<T>` that is being returned in order to allow access to the data if poisoning is not desired. This also means that the lock is *always* held upon returning from `.lock()`. A new type, `PoisonError`, was added with one method `into_guard` which can consume the assertion that a lock is poisoned to gain access to the underlying data. This is a breaking change because the signatures of these methods have changed, often incompatible ways. One major difference is that the `wait` methods on a condition variable now consume the guard and return it in as a `LockResult` to indicate whether the lock was poisoned while waiting. Most code can be updated by calling `.unwrap()` on the return value of `.lock()`. [breaking-change]
2014-12-29std: Stabilize the prelude moduleAlex Crichton-44/+59
This commit is an implementation of [RFC 503][rfc] which is a stabilization story for the prelude. Most of the RFC was directly applied, removing reexports. Some reexports are kept around, however: * `range` remains until range syntax has landed to reduce churn. * `Path` and `GenericPath` remain until path reform lands. This is done to prevent many imports of `GenericPath` which will soon be removed. * All `io` traits remain until I/O reform lands so imports can be rewritten all at once to `std::io::prelude::*`. This is a breaking change because many prelude reexports have been removed, and the RFC can be consulted for the exact list of removed reexports, as well as to find the locations of where to import them. [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0503-prelude-stabilization.md [breaking-change] Closes #20068
2014-12-29Fallout from globs/re-export/shadowing changeNick Cameron-1/+1
2014-12-28Rename TaskRng to ThreadRngSimonas Kazlauskas-1/+1
Since runtime is removed, rust has no tasks anymore and everything is moving from being task-* to thread-*. Let’s rename TaskRng as well! * Rename TaskRng to ThreadRng * Rename task_rng to thread_rng [breaking-change]
2014-12-26s/task/thread/gSteve Klabnik-16/+16
A part of #20038
2014-12-26Make Barrier and Condvar Sync/SendFlavio Percoco-8/+32