about summary refs log tree commit diff
path: root/library/std/src/sync
AgeCommit message (Collapse)AuthorLines
2023-07-31Rollup merge of #109318 - joboet:better_fmt_placeholder, r=dtolnayMatthias Krüger-20/+12
Make `Debug` representations of `[Lazy, Once]*[Cell, Lock]` consistent with `Mutex` and `RwLock` `Mutex` prints `<locked>` as a field value when its inner value cannot be accessed, but the lazy types print a fixed string like "`OnceCell(Uninit)`". This could cause confusion if the inner type is a unit type named `Uninit` and does not respect the pretty-printing flag. With this change, the format message is now "`OnceCell(<uninit>)`", consistent with `Mutex`.
2023-07-30Rollup merge of #109075 - joboet:lazylock_backtrace, r=workingjubileeJubilee-0/+9
Use `LazyLock` to lazily resolve backtraces By using TAIT to name the initializing closure, `LazyLock` can be used to replace the current `LazilyResolvedCapture`.
2023-07-30Fix the example in document for WaitTimeoutResult::timed_outyukang-10/+8
2023-07-25docs(LazyLock): add example pass local LazyLock variable to structDragonBillow-0/+20
Signed-off-by: DragonBillow <DragonBillow@outlook.com>
2023-07-19avoid tls access while iterating through mpsc thread entriesIbraheem Ahmed-20/+26
2023-07-18support for mips32r6 as a target_arch valuechenx97-0/+2
2023-07-18support for mips64r6 as a target_arch valuechenx97-0/+2
2023-07-12Replace version placeholder to 1.72Mark Rousskov-1/+1
2023-06-30std docs: factorize literal in Barrier exampleGuilliam Xavier-6/+8
2023-06-10implement `Sync` for `mpsc::Sender`Ibraheem Ahmed-2/+2
2023-06-01doc: improve explanationTshepang Mbambo-1/+1
2023-05-03Remove unnecessary Send boundGil Shoshan-3/+3
2023-04-28replace version placeholdersPietro Albini-21/+21
2023-04-27std: use `LazyLock` to lazily resolve backtracesjoboet-0/+9
2023-04-26Rollup merge of #110419 - jsoref:spelling-library, r=jyn514Matthias Krüger-2/+2
Spelling library Split per https://github.com/rust-lang/rust/pull/110392 I can squash once people are happy w/ the changes. It's really uncommon for large sets of changes to be perfectly acceptable w/o at least some changes. I probably won't have time to respond until tomorrow or the next day
2023-04-26Spelling library/Josh Soref-2/+2
* advance * aligned * borrowed * calculate * debugable * debuggable * declarations * desugaring * documentation * enclave * ignorable * initialized * iterator * kaboom * monomorphization * nonexistent * optimizer * panicking * process * reentrant * rustonomicon * the * uninitialized Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-24Auto merge of #106152 - SUPERCILEX:lazycell, r=Amanieubors-1/+37
Add LazyCell::into_inner This enables uses cases that need to extract the evaluated value and do something owned with it.
2023-04-19std: make `Debug` representations of `[Lazy, Once]*[Cell, Lock]` consistent ↵joboet-20/+12
with `Mutex` and `RwLock` `Mutex` prints `<locked>` as a field value when its inner value cannot be accessed, but the lazy types print a fixed string like "`OnceCell(Uninit)`". This could cause confusion if the inner type is a unit type named `Uninit` and does not respect the pretty-printing flag. With this change, the format message is now "`OnceCell(<uninit>)`", consistent with `Mutex`.
2023-04-16rm const traits in libcoreDeadbeef-2/+1
2023-04-14Add Lazy{Cell,Lock}::into_innerAlex Saveau-1/+37
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2023-04-08sync::mpsc: synchronize receiver disconnect with initializationPetros Angelatos-0/+12
Receiver disconnection relies on the incorrect assumption that `head.index != tail.index` implies that the channel is initialized (i.e `head.block` and `tail.block` point to allocated blocks). However, it can happen that `head.index != tail.index` and `head.block == null` at the same time which leads to a segfault when a channel is dropped in that state. This can happen because initialization is performed in two steps. First, the tail block is allocated and the `tail.block` is set. If that is successful `head.block` is set to the same pointer. Importantly, initialization is skipped if `tail.block` is not null. Therefore we can have the following situation: 1. Thread A starts to send the first value of the channel, observes that `tail.block` is null and begins initialization. It sets `tail.block` to point to a newly allocated block and then gets preempted. `head.block` is still null at this point. 2. Thread B starts to send the second value of the channel, observes that `tail.block` *is not* null and proceeds with writing its value in the allocated tail block and sets `tail.index` to 1. 3. Thread B drops the receiver of the channel which observes that `head.index != tail.index` (0 and 1 respectively), therefore there must be messages to drop. It starts traversing the linked list from `head.block` which is still a null pointer, leading to a segfault. This PR fixes this problem by waiting for initialization to complete when `head.index != tail.index` and the `head.block` is still null. A similar check exists in `start_recv` for similar reasons. Fixes #110001 Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
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