about summary refs log tree commit diff
path: root/src/libstd/sync
AgeCommit message (Collapse)AuthorLines
2016-10-01std: Correct stability attributes for some implementationsOliver Middleton-2/+0
These are displayed by rustdoc so should be correct.
2016-09-30Ignore various entire test modules on emscriptenBrian Anderson-26/+5
2016-09-30Ignore entire test modules on emscripten instead of individual testsBrian Anderson-66/+3
2016-09-30Ignore lots and lots of std tests on emscriptenBrian Anderson-0/+89
2016-09-22Rollup merge of #36423 - GuillaumeGomez:eq_impl, r=pnkfelixJonathan Turner-1/+1
Add missing Eq implementations Part of #36301.
2016-09-18Add missing Eq implementationsGuillaume Gomez-1/+1
2016-09-14Rollup merge of #36396 - athulappadan:Default-docs, r=blussGuillaume Gomez-0/+3
Documentation of what Default does for each type Addresses #36265 I haven't changed the following types due to doubts: 1)src/libstd/ffi/c_str.rs 2)src/libcore/iter/sources.rs 3)src/libcore/hash/mod.rs 4)src/libcore/hash/mod.rs 5)src/librustc/middle/privacy.rs r? @steveklabnik
2016-09-11Use question_mark feature in libstd.Ahmed Charles-3/+2
2016-09-11Documentation of what does for each typeathulappadan-0/+3
2016-09-03Auto merge of #36104 - KiChjang:issue-35847, r=brsonbors-4/+24
Fix illegal instruction caused by overflow in channel cloning Fixes #35847. r? @alexcrichton
2016-08-30Auto merge of #35048 - tmiasko:monotonic-wait-timeout, r=alexcrichtonbors-1/+13
Use monotonic time in condition variables. Configure condition variables to use monotonic time using pthread_condattr_setclock on systems where this is possible. This fixes the issue when thread waiting on condition variable is woken up too late when system time is moved backwards.
2016-08-29Fix illegal instruction caused by overflow in channel cloningKeith Yeung-4/+24
2016-08-24Use `#[prelude_import]` in `libstd`.Jeffrey Seyfried-31/+0
2016-08-19std: Stabilize APIs for the 1.12 releaseAlex Crichton-4/+4
Stabilized * `Cell::as_ptr` * `RefCell::as_ptr` * `IpAddr::is_{unspecified,loopback,multicast}` * `Ipv6Addr::octets` * `LinkedList::contains` * `VecDeque::contains` * `ExitStatusExt::from_raw` - both on Unix and Windows * `Receiver::recv_timeout` * `RecvTimeoutError` * `BinaryHeap::peek_mut` * `PeekMut` * `iter::Product` * `iter::Sum` * `OccupiedEntry::remove_entry` * `VacantEntry::into_key` Deprecated * `Cell::as_unsafe_cell` * `RefCell::as_unsafe_cell` * `OccupiedEntry::remove_pair` Closes #27708 cc #27709 Closes #32313 Closes #32630 Closes #32713 Closes #34029 Closes #34392 Closes #34285 Closes #34529
2016-08-19Document that Condvar makes the best effort to use monotonic clock.Tomasz Miąsko-0/+8
2016-07-31Use monotonic time with condition variables.Tomasz Miąsko-1/+5
Configure condition variables to use monotonic time using pthread_condattr_setclock on systems where this is possible. This fixes the issue when thread waiting on condition variable is woken up too late when system time is moved backwards.
2016-07-21Auto merge of #34724 - mitchmindtree:mpsc_receiver_try_recv, r=alexcrichtonbors-0/+56
Add a method to the mpsc::Receiver for producing a non-blocking iterator Currently, the `mpsc::Receiver` offers methods for receiving values in both blocking (`recv`) and non-blocking (`try_recv`) flavours. However only blocking iteration over values is supported. This PR adds a non-blocking iterator to complement the `try_recv` method, just as the blocking iterator complements the `recv` method. Use-case ------------- I predominantly use rust in my work on real-time systems and in particular real-time audio generation/processing. I use `mpsc::channel`s to communicate between threads in a purely non-blocking manner. I.e. I might send messages from the GUI thread to the audio thread to update the state of the dsp-graph, or from the audio thread to the GUI thread to display the RMS of each node. These are just a couple examples (I'm probably using 30+ channels across my various projects). I almost exclusively use the `mpsc::Receiver::try_recv` method to avoid blocking any of the real-time threads and causing unwanted glitching/stuttering. Now that I mention it, I can't think of a single time that I personally have used the `recv` method (though I can of course see why it would be useful, and perhaps the common case for many people). As a result of this experience, I can't help but feel there is a large hole in the `Receiver` API. | blocking | non-blocking | |------------|--------------------| | `recv` | `try_recv` | | `iter` | 🙀 | For the most part, I've been working around this using `while let Ok(v) = r.try_recv() { ... }`, however as nice as this is, it is clearly no match for the Iterator API. As an example, in the majority of my channel use cases I only want to check for *n* number of messages before breaking from the loop so that I don't miss the audio IO callback or hog the GUI thread for too long when an unexpectedly large number of messages are sent. Currently, I have to write something like this: ```rust let mut take = 100; while let Ok(msg) = rx.try_recv() { // Do stuff with msg if take == 0 { break; } take -= 1; } ``` or wrap the `try_recv` call in a `Range<usize>`/`FilterMap` iterator combo. On the other hand, this PR would allow for the following: ```rust for msg in rx.try_iter().take(100) { // Do stuff with msg } ``` I imagine this might also be useful to game devs, embedded or anyone doing message passing across real-time threads.
2016-07-21Fix issue in receiver_try_iter test where response sender would panic ↵mitchmindtree-3/+3
instead of break from the loop
2016-07-20Add the missing tracking issue field for #34931 to the receiver_try_iter ↵mitchmindtree-3/+3
stability attributes
2016-07-15Rollup merge of #34456 - tbu-:pr_ptr_null, r=aturonGuillaume Gomez-1/+2
Use `ptr::{null, null_mut}` instead of `0 as *{const, mut}`
2016-07-12std: Clean out deprecated APIsAlex Crichton-680/+170
This primarily removes a lot of `sync::Static*` APIs and rejiggers the associated implementations. While doing this it was discovered that the `is_poisoned` method can actually result in a data race for the Mutex/RwLock primitives, so the inner `Cell<bool>` was changed to an `AtomicBool` to prevent the associated data race. Otherwise the usage/gurantees should be the same they were before.
2016-07-12Use `ptr::{null, null_mut}` instead of `0 as *{const, mut}`Tobias Bucher-1/+2
2016-07-08Check for data in Receiver::try_recv before reporting disconnectAndrew-1/+10
2016-07-09Add the unstable attribute to the new mpsc::Receiver::try_iter APImitchmindtree-0/+3
2016-07-09Add a test for Receiver::try_itermitchmindtree-0/+28
2016-07-08add a non blocking iterator for the mpsc::Receivermitchmindtree-0/+25
Currently, the `mpsc::Receiver` offers methods for receiving values in both blocking (`recv`) and non-blocking (`try_recv`) flavours. However only blocking iteration over values is supported. This commit adds a non-blocking iterator to complement the `try_recv` method, just as the blocking iterator complements the `recv` method.
2016-06-22std: sync: Implement recv_timeout()Emilio Cobos Álvarez-42/+396
2016-06-09fix stdtestAriel Ben-Yehuda-5/+8
2016-06-03Auto merge of #33861 - Amanieu:lock_elision_fix, r=alexcrichtonbors-1/+5
Make sure Mutex and RwLock can't be re-locked on the same thread Fixes #33770 r? @alexcrichton
2016-06-02Fix undefined behavior when re-locking a mutex from the same threadAmanieu d'Antras-1/+5
The only applies to pthread mutexes. We solve this by creating the mutex with the PTHREAD_MUTEX_NORMAL type, which guarantees that re-locking from the same thread will deadlock.
2016-05-30std: Clean out old unstable + deprecated APIsAlex Crichton-104/+1
These should all have been deprecated for at least one cycle, so this commit cleans them all out.
2016-05-25Auto merge of #33699 - alexcrichton:stabilize-1.10, r=aturonbors-2/+85
std: Stabilize APIs for the 1.10 release This commit applies the FCP decisions made by the libs team for the 1.10 cycle, including both new stabilizations and deprecations. Specifically, the list of APIs is: Stabilized: * `os::windows::fs::OpenOptionsExt::access_mode` * `os::windows::fs::OpenOptionsExt::share_mode` * `os::windows::fs::OpenOptionsExt::custom_flags` * `os::windows::fs::OpenOptionsExt::attributes` * `os::windows::fs::OpenOptionsExt::security_qos_flags` * `os::unix::fs::OpenOptionsExt::custom_flags` * `sync::Weak::new` * `Default for sync::Weak` * `panic::set_hook` * `panic::take_hook` * `panic::PanicInfo` * `panic::PanicInfo::payload` * `panic::PanicInfo::location` * `panic::Location` * `panic::Location::file` * `panic::Location::line` * `ffi::CStr::from_bytes_with_nul` * `ffi::CStr::from_bytes_with_nul_unchecked` * `ffi::FromBytesWithNulError` * `fs::Metadata::modified` * `fs::Metadata::accessed` * `fs::Metadata::created` * `sync::atomic::Atomic{Usize,Isize,Bool,Ptr}::compare_exchange` * `sync::atomic::Atomic{Usize,Isize,Bool,Ptr}::compare_exchange_weak` * `collections::{btree,hash}_map::{Occupied,Vacant,}Entry::key` * `os::unix::net::{UnixStream, UnixListener, UnixDatagram, SocketAddr}` * `SocketAddr::is_unnamed` * `SocketAddr::as_pathname` * `UnixStream::connect` * `UnixStream::pair` * `UnixStream::try_clone` * `UnixStream::local_addr` * `UnixStream::peer_addr` * `UnixStream::set_read_timeout` * `UnixStream::set_write_timeout` * `UnixStream::read_timeout` * `UnixStream::write_Timeout` * `UnixStream::set_nonblocking` * `UnixStream::take_error` * `UnixStream::shutdown` * Read/Write/RawFd impls for `UnixStream` * `UnixListener::bind` * `UnixListener::accept` * `UnixListener::try_clone` * `UnixListener::local_addr` * `UnixListener::set_nonblocking` * `UnixListener::take_error` * `UnixListener::incoming` * RawFd impls for `UnixListener` * `UnixDatagram::bind` * `UnixDatagram::unbound` * `UnixDatagram::pair` * `UnixDatagram::connect` * `UnixDatagram::try_clone` * `UnixDatagram::local_addr` * `UnixDatagram::peer_addr` * `UnixDatagram::recv_from` * `UnixDatagram::recv` * `UnixDatagram::send_to` * `UnixDatagram::send` * `UnixDatagram::set_read_timeout` * `UnixDatagram::set_write_timeout` * `UnixDatagram::read_timeout` * `UnixDatagram::write_timeout` * `UnixDatagram::set_nonblocking` * `UnixDatagram::take_error` * `UnixDatagram::shutdown` * RawFd impls for `UnixDatagram` * `{BTree,Hash}Map::values_mut` * `<[_]>::binary_search_by_key` Deprecated: * `StaticCondvar` - this, and all other static synchronization primitives below, are usable today through the lazy-static crate on stable Rust today. Additionally, we'd like the non-static versions to be directly usable in a static context one day, so they're unlikely to be the final forms of the APIs in any case. * `CONDVAR_INIT` * `StaticMutex` * `MUTEX_INIT` * `StaticRwLock` * `RWLOCK_INIT` * `iter::Peekable::is_empty` Closes #27717 Closes #27720 Closes #30014 Closes #30425 Closes #30449 Closes #31190 Closes #31399 Closes #31767 Closes #32111 Closes #32281 Closes #32312 Closes #32551 Closes #33018
2016-05-24std: Stabilize APIs for the 1.10 releaseAlex Crichton-2/+85
This commit applies the FCP decisions made by the libs team for the 1.10 cycle, including both new stabilizations and deprecations. Specifically, the list of APIs is: Stabilized: * `os::windows::fs::OpenOptionsExt::access_mode` * `os::windows::fs::OpenOptionsExt::share_mode` * `os::windows::fs::OpenOptionsExt::custom_flags` * `os::windows::fs::OpenOptionsExt::attributes` * `os::windows::fs::OpenOptionsExt::security_qos_flags` * `os::unix::fs::OpenOptionsExt::custom_flags` * `sync::Weak::new` * `Default for sync::Weak` * `panic::set_hook` * `panic::take_hook` * `panic::PanicInfo` * `panic::PanicInfo::payload` * `panic::PanicInfo::location` * `panic::Location` * `panic::Location::file` * `panic::Location::line` * `ffi::CStr::from_bytes_with_nul` * `ffi::CStr::from_bytes_with_nul_unchecked` * `ffi::FromBytesWithNulError` * `fs::Metadata::modified` * `fs::Metadata::accessed` * `fs::Metadata::created` * `sync::atomic::Atomic{Usize,Isize,Bool,Ptr}::compare_exchange` * `sync::atomic::Atomic{Usize,Isize,Bool,Ptr}::compare_exchange_weak` * `collections::{btree,hash}_map::{Occupied,Vacant,}Entry::key` * `os::unix::net::{UnixStream, UnixListener, UnixDatagram, SocketAddr}` * `SocketAddr::is_unnamed` * `SocketAddr::as_pathname` * `UnixStream::connect` * `UnixStream::pair` * `UnixStream::try_clone` * `UnixStream::local_addr` * `UnixStream::peer_addr` * `UnixStream::set_read_timeout` * `UnixStream::set_write_timeout` * `UnixStream::read_timeout` * `UnixStream::write_Timeout` * `UnixStream::set_nonblocking` * `UnixStream::take_error` * `UnixStream::shutdown` * Read/Write/RawFd impls for `UnixStream` * `UnixListener::bind` * `UnixListener::accept` * `UnixListener::try_clone` * `UnixListener::local_addr` * `UnixListener::set_nonblocking` * `UnixListener::take_error` * `UnixListener::incoming` * RawFd impls for `UnixListener` * `UnixDatagram::bind` * `UnixDatagram::unbound` * `UnixDatagram::pair` * `UnixDatagram::connect` * `UnixDatagram::try_clone` * `UnixDatagram::local_addr` * `UnixDatagram::peer_addr` * `UnixDatagram::recv_from` * `UnixDatagram::recv` * `UnixDatagram::send_to` * `UnixDatagram::send` * `UnixDatagram::set_read_timeout` * `UnixDatagram::set_write_timeout` * `UnixDatagram::read_timeout` * `UnixDatagram::write_timeout` * `UnixDatagram::set_nonblocking` * `UnixDatagram::take_error` * `UnixDatagram::shutdown` * RawFd impls for `UnixDatagram` * `{BTree,Hash}Map::values_mut` * `<[_]>::binary_search_by_key` Deprecated: * `StaticCondvar` - this, and all other static synchronization primitives below, are usable today through the lazy-static crate on stable Rust today. Additionally, we'd like the non-static versions to be directly usable in a static context one day, so they're unlikely to be the final forms of the APIs in any case. * `CONDVAR_INIT` * `StaticMutex` * `MUTEX_INIT` * `StaticRwLock` * `RWLOCK_INIT` * `iter::Peekable::is_empty` Closes #27717 Closes #27720 cc #27784 (but encode methods still exist) Closes #30014 Closes #30425 Closes #30449 Closes #31190 Closes #31399 Closes #31767 Closes #32111 Closes #32281 Closes #32312 Closes #32551 Closes #33018
2016-05-20update tracking issue for once_poisonAlex Burka-3/+3
The tracking issue for once_poison was noted as #31688 which was closed, so it now points to the new #33577.
2016-05-15Rollup merge of #33565 - Amanieu:once_doc, r=GuillaumeGomezManish Goregaokar-1/+0
Fix typo in std::sync::Once documentation
2016-05-11Fix typo in std::sync::Once documentationAmanieu d'Antras-1/+0
2016-05-11Export OnceState from libstdAmanieu d'Antras-1/+1
2016-05-09Utilize `Result::unwrap_err` in more places.Corey Farwell-1/+1
2016-05-07Rollup merge of #33459 - frewsxcv:patch-29, r=guillaumegomezSteve Klabnik-2/+2
Indicate struct names are code-like in doc-comment.
2016-05-07Rollup merge of #33456 - CryZe:barrier-wait-docs, r=GuillaumeGomezSteve Klabnik-1/+1
Fix Typo in Barrier::wait documentation This should be `have` instead of `has`.
2016-05-06Indicate struct names are code-like in doc-comment.Corey Farwell-2/+2
2016-05-06Fix Typo in Barrier::wait documentationChristopher Serr-1/+1
This should be `have` instead of `has`.
2016-04-22doc: that line was too longTshepang Lekhonkhobe-2/+2
2016-04-17Add a comment about locking a `Mutex` multiple timesTobias Bucher-0/+9
Fixes #32260.
2016-04-15Auto merge of #32785 - tbu-:pr_more_defaults, r=alexcrichtonbors-0/+21
Implement `Default` for more types in the standard library Also add `Hash` to `std::cmp::Ordering` and most possible traits to `fmt::Error`.
2016-04-15Implement `Default` for more types in the standard libraryTobias Bucher-0/+21
Also add `Hash` to `std::cmp::Ordering` and most possible traits to `fmt::Error`.
2016-04-11std: Stabilize APIs for the 1.9 releaseAlex Crichton-3/+3
This commit applies all stabilizations, renamings, and deprecations that the library team has decided on for the upcoming 1.9 release. All tracking issues have gone through a cycle-long "final comment period" and the specific APIs stabilized/deprecated are: Stable * `std::panic` * `std::panic::catch_unwind` (renamed from `recover`) * `std::panic::resume_unwind` (renamed from `propagate`) * `std::panic::AssertUnwindSafe` (renamed from `AssertRecoverSafe`) * `std::panic::UnwindSafe` (renamed from `RecoverSafe`) * `str::is_char_boundary` * `<*const T>::as_ref` * `<*mut T>::as_ref` * `<*mut T>::as_mut` * `AsciiExt::make_ascii_uppercase` * `AsciiExt::make_ascii_lowercase` * `char::decode_utf16` * `char::DecodeUtf16` * `char::DecodeUtf16Error` * `char::DecodeUtf16Error::unpaired_surrogate` * `BTreeSet::take` * `BTreeSet::replace` * `BTreeSet::get` * `HashSet::take` * `HashSet::replace` * `HashSet::get` * `OsString::with_capacity` * `OsString::clear` * `OsString::capacity` * `OsString::reserve` * `OsString::reserve_exact` * `OsStr::is_empty` * `OsStr::len` * `std::os::unix::thread` * `RawPthread` * `JoinHandleExt` * `JoinHandleExt::as_pthread_t` * `JoinHandleExt::into_pthread_t` * `HashSet::hasher` * `HashMap::hasher` * `CommandExt::exec` * `File::try_clone` * `SocketAddr::set_ip` * `SocketAddr::set_port` * `SocketAddrV4::set_ip` * `SocketAddrV4::set_port` * `SocketAddrV6::set_ip` * `SocketAddrV6::set_port` * `SocketAddrV6::set_flowinfo` * `SocketAddrV6::set_scope_id` * `<[T]>::copy_from_slice` * `ptr::read_volatile` * `ptr::write_volatile` * The `#[deprecated]` attribute * `OpenOptions::create_new` Deprecated * `std::raw::Slice` - use raw parts of `slice` module instead * `std::raw::Repr` - use raw parts of `slice` module instead * `str::char_range_at` - use slicing plus `chars()` plus `len_utf8` * `str::char_range_at_reverse` - use slicing plus `chars().rev()` plus `len_utf8` * `str::char_at` - use slicing plus `chars()` * `str::char_at_reverse` - use slicing plus `chars().rev()` * `str::slice_shift_char` - use `chars()` plus `Chars::as_str` * `CommandExt::session_leader` - use `before_exec` instead. Closes #27719 cc #27751 (deprecating the `Slice` bits) Closes #27754 Closes #27780 Closes #27809 Closes #27811 Closes #27830 Closes #28050 Closes #29453 Closes #29791 Closes #29935 Closes #30014 Closes #30752 Closes #31262 cc #31398 (still need to deal with `before_exec`) Closes #31405 Closes #31572 Closes #31755 Closes #31756
2016-03-28Rollup merge of #32507 - klingtnet:master, r=steveklabnikSteve Klabnik-2/+7
Fix missing console output in `Barrier` example The `println!` calls in the previous version were never shown (at least not in the playpen) because the main thread is finished before all the spawned child threads were synchronized. This commit adds a join for each thread handle to wait in the main thread until all child threads are finished. r? @steveklabnik
2016-03-26std: Rewrite Once with poisoningAlex Crichton-56/+363
This commit rewrites the `std::sync::Once` primitive with poisoning in mind in light of #31688. Currently a panic in the initialization closure will cause future initialization closures to run, but the purpose of a Once is usually to initialize some global state so it's highly likely that the global state is corrupt if a panic happened. The same strategy of a mutex is taken where a panic is propagated by default. A new API, `call_once_force`, was added to subvert panics like is available on Mutex as well (for when panicking is handled internally). Adding this support was a significant enough change to the implementation that it was just completely rewritten from scratch, primarily to avoid using a `StaticMutex` which needs to have `destroy()` called on it at some point (a pain to do). Closes #31688
2016-03-26Fix missing console output in `Barrier` exampleAndreas Linz-2/+7
The `println!` calls in the previous version were never shown (at least not in the playpen) because the main thread is finished before all the spawned child threads were synchronized. This commit adds a join for each thread handle to wait in the main thread until all child threads are finished.