about summary refs log tree commit diff
path: root/library/std/src/sync
AgeCommit message (Collapse)AuthorLines
2023-03-29Documentation updates to better share the purpose of OnceCell/OnceLockTrevor Gross-1/+4
2023-03-29Stabilize a portion of 'once_cell'Trevor Gross-51/+36
Move items not part of this stabilization to 'lazy_cell' or 'once_cell_try'
2023-03-24Rollup merge of #109142 - the8472:mutex-block-docs, r=cuviperMatthias Krüger-7/+17
Add block-based mutex unlocking example This modifies the existing example in the Mutex docs to show both `drop()` and block based early unlocking. Alternative to #81872, which is getting closed.
2023-03-21Rollup merge of #108164 - joboet:discard_messages_mpmc_array, r=AmanieuMatthias Krüger-26/+98
Drop all messages in bounded channel when destroying the last receiver Fixes #107466 by splitting the `disconnect` function for receivers/transmitters and dropping all messages in `disconnect_receivers` like the unbounded channel does. Since all receivers must be dropped before the channel is, the messages will already be discarded at that point, so the `Drop` implementation for the channel can be removed. ``@rustbot`` label +T-libs +A-concurrency
2023-03-20Apply suggestions from code reviewthe8472-3/+3
Co-authored-by: Josh Stone <cuviper@gmail.com>
2023-03-20Add block-based mutex unlocking exampleThe 8472-7/+17
2023-03-15unequal → not equalgimbles-1/+1
2023-03-14std: leak remaining messages in bounded channel if message destructor panicsjoboet-66/+42
2023-02-26std: disconnect senders before discarding messagesjoboet-4/+5
2023-02-18Auto merge of #107329 - joboet:optimize_lazylock, r=m-ou-sebors-17/+87
Optimize `LazyLock` size The initialization function was unnecessarily stored separately from the data to be initialized. Since both cannot exist at the same time, a `union` can be used, with the `Once` acting as discriminant. This unfortunately requires some extra methods on `Once` so that `Drop` can be implemented correctly and efficiently. `@rustbot` label +T-libs +A-atomic
2023-02-17std: add regression test for #107466joboet-0/+13
Tests that messages are immediately dropped once the last receiver is destroyed.
2023-02-17std: drop all messages in bounded channel when destroying the last receiverjoboet-27/+109
2023-01-27std: add safety comment in `LazyLock::get`joboet-1/+8
2023-01-27std: fix `Debug` implementation on `LazyLock`joboet-8/+5
2023-01-26std: optimize `LazyLock` sizejoboet-17/+83
2023-01-14remove optimistic spinning from `mpsc::SyncSender`Ibraheem Ahmed-23/+7
2023-01-13Rollup merge of #106701 - ibraheemdev:sync-sender-spin, r=AmanieuMatthias Krüger-33/+49
Fix `mpsc::SyncSender` spinning behavior Resolves https://github.com/rust-lang/rust/issues/106668.
2023-01-11rework and document backoff behavior of `sync::mpsc`Ibraheem Ahmed-31/+30
2023-01-10add `SyncSender::send_timeout` testIbraheem Ahmed-1/+18
2023-01-10fix `SyncSender` spinning behaviorIbraheem Ahmed-1/+1
2023-01-09std test: better type name, clarifying commentRalf Jung-1/+1
2023-01-04Update rand in the stdlib tests, and remove the getrandom feature from itThom Chiovoloni-2/+2
2022-12-30Auto merge of #105651 - tgross35:once-cell-inline, r=m-ou-sebors-1/+21
Add #[inline] markers to once_cell methods Added inline markers to all simple methods under the `once_cell` feature. Relates to #74465 and #105587 This should not block #105587
2022-12-28Rollup merge of #104402 - joboet:sync_remutex, r=m-ou-seMatthias Krüger-0/+241
Move `ReentrantMutex` to `std::sync` If I understand #84187 correctly, `sys_common` should not contain platform-independent code, even if it is private.
2022-12-28Rollup merge of #104708 - ↵fee1-dead-1/+1
jonasspinner:fix-backoff-doc-to-match-implementation, r=compiler-errors Fix backoff doc to match implementation The commit 8dddb2294310ad3e8ce0b2af735a702ad72a9a99 in the crossbeam-channel PR (#93563) changed the backoff strategy to be quadratic instead of exponential. This updates the doc to prevent confusion.
2022-12-27Rollup merge of #103718 - matklad:infer-lazy, r=dtolnayMichael Goulet-4/+7
More inference-friendly API for lazy The signature for new was ``` fn new<F>(f: F) -> Lazy<T, F> ``` Notably, with `F` unconstrained, `T` can be literally anything, and just `let _ = Lazy::new(|| 92)` would not typecheck. This historiacally was a necessity -- `new` is a `const` function, it couldn't have any bounds. Today though, we can move `new` under the `F: FnOnce() -> T` bound, which gives the compiler enough data to infer the type of T from closure.
2022-12-13Add #[inline] marker to OnceCell/LazyCell/OnceLock/LazyLockTrevor Gross-1/+21
2022-12-06Rollup merge of #105243 - RalfJung:no-op-let, r=Mark-SimulacrumMatthias Krüger-9/+3
remove no-op 'let _ = ' Also see the discussion at https://github.com/rust-lang/rust/pull/93563#discussion_r1034057555. I don't know why these `Drop` implementations exist to begin with, given that their body does literally nothing, but did not want to change that. (It might affect dropck.) Cc `````@ibraheemdev````` `````@Amanieu`````
2022-12-05fix dupe word typosRageking8-1/+1
2022-12-04remove no-op 'let _ = 'Ralf Jung-9/+3
2022-11-22rustdoc: Fix backoff doc to match implementationJonas Spinner-1/+1
2022-11-19Rollup merge of #104528 - WaffleLapkin:lazy_lock_docfix, r=matkladDylan DPC-3/+7
Properly link `{Once,Lazy}{Cell,Lock}` in docs See https://github.com/rust-lang/rust/issues/74465#issuecomment-1317947443
2022-11-17Properly link `{Once,Lazy}{Cell,Lock}` in docsMaybe Waffle-3/+7
2022-11-14std: move `ReentrantMutex` to `sync`joboet-0/+241
2022-11-14avoid memory leak in mpsc testRalf Jung-2/+3
2022-11-13Auto merge of #93563 - ibraheemdev:crossbeam-channel, r=Amanieubors-2826/+2695
Merge crossbeam-channel into `std::sync::mpsc` This PR imports the [`crossbeam-channel`](https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-channel#crossbeam-channel) crate into the standard library as a private module, `sync::mpmc`. `sync::mpsc` is now implemented as a thin wrapper around `sync::mpmc`. The primary purpose of this PR is to resolve https://github.com/rust-lang/rust/issues/39364. The public API intentionally remains the same. The reason https://github.com/rust-lang/rust/issues/39364 has not been fixed in over 5 years is that the current channel is *incredibly* complex. It was written many years ago and has sat mostly untouched since. `crossbeam-channel` has become the most popular alternative on crates.io, amassing over 30 million downloads. While crossbeam's channel is also complex, like all fast concurrent data structures, it avoids some of the major issues with the current implementation around dynamic flavor upgrades. The new implementation decides on the datastructure to be used when the channel is created, and the channel retains that structure until it is dropped. Replacing `sync::mpsc` with a simpler, less performant implementation has been discussed as an alternative. However, Rust touts itself as enabling *fearless concurrency*, and having the standard library feature a subpar implementation of a core concurrency primitive doesn't feel right. The argument is that slower is better than broken, but this PR shows that we can do better. As mentioned before, the primary purpose of this PR is to fix https://github.com/rust-lang/rust/issues/39364, and so the public API intentionally remains the same. *After* that problem is fixed, the fact that `sync::mpmc` now exists makes it easier to fix the primary limitation of `mpsc`, the fact that it only supports a single consumer. spmc and mpmc are two other common concurrency patterns, and this change enables a path to deprecating `mpsc` and exposing a general `sync::channel` module that supports multiple consumers. It also implements other useful methods such as `send_timeout`. That said, exposing MPMC and other new functionality is mostly out of scope for this PR, and it would be helpful if discussion stays on topic :) For what it's worth, the new implementation has also been shown to be more performant in [some basic benchmarks](https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-channel/benchmarks#results). cc `@taiki-e` r? rust-lang/libs
2022-11-12avoid calling `thread::current` in channel destructorIbraheem Ahmed-13/+11
2022-11-12Auto merge of #103150 - joboet:remove_lock_wrappers, r=m-ou-sebors-19/+11
Remove lock wrappers in `sys_common` This moves the lazy allocation to `sys` (SGX and UNIX). While this leads to a bit more verbosity, it will simplify future improvements by making room in `sys_common` for platform-independent implementations. This also removes the condvar check on SGX as it is not necessary for soundness and will be removed anyway once mutex has been made movable. For simplicity's sake, `libunwind` also uses lazy allocation now on SGX. This will require an update to the C definitions before merging this (CC `@raoulstrackx).` r? `@m-ou-se`
2022-11-09tidyIbraheem Ahmed-5/+4
2022-11-09spin less in `mpsc::SyncSender::send`Ibraheem Ahmed-1/+1
2022-11-09remove extra spinning from `mpsc` parkerIbraheem Ahmed-15/+0
2022-11-09`sync::mpsc`: quadratic backoffIbraheem Ahmed-2/+3
2022-11-09`sync::mpsc`: reload state after spinning on CAS failureIbraheem Ahmed-8/+8
2022-11-09remove extra spinning from `mpsc::Receiver::recv`Ibraheem Ahmed-26/+6
2022-11-09remove mention of rust-lang#39364 from mpsc docsIbraheem Ahmed-28/+0
2022-11-09add test case for rust-lang#39364Ibraheem Ahmed-0/+14
2022-11-09implement `sync::mpsc` as a wrapper around `sync::mpmc`Ibraheem Ahmed-2798/+24
2022-11-09initial port of crossbeam-channelIbraheem Ahmed-0/+2694
2022-11-08clarify licensing situation of mpsc and spsc queuePietro Albini-2/+17
2022-11-06std: remove lock wrappers in `sys_common`joboet-19/+11