summary refs log tree commit diff
path: root/library/std/src/sync
AgeCommit message (Collapse)AuthorLines
2023-12-10Auto merge of #118692 - surechen:remove_unused_imports, r=petrochenkovbors-2/+0
remove redundant imports detects redundant imports that can be eliminated. for #117772 : In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR. r? `@petrochenkov`
2023-12-10remove redundant importssurechen-2/+0
detects redundant imports that can be eliminated. for #117772 : In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR.
2023-12-10Fix typo in `std::sync::Mutex` examplenaglis-1/+1
2023-12-08OnceLock: Rework example, statics aren't droppedIan Rees-14/+25
2023-11-25Update `OnceLock` documentation to give a concrete 'lazy static' example, ↵Corey Farwell-9/+41
and expand on existing example.
2023-10-24Add T: ?Sized to RwLock*Guards' Debug impls.Zachary S-2/+2
2023-10-13Implement `OnceCell/Lock::try_insert()`daxpedda-3/+40
2023-10-06Minor doc clarification in Once::call_oncePeter Hall-1/+1
2023-09-19Replace 'mutex' with 'lock' in RwLock documentationKriskras99-2/+2
When copying the documentation for `clear_poison` from Mutex, not every occurence of 'mutex' was replaced with 'lock'.
2023-08-18Remove Drop impl of mpsc Receiver and (Sync)SenderBen Schulz-15/+0
2023-08-12Update Sender documentation for SyncGurinder Singh-3/+2
2023-08-01[library/std] Replace condv while loop with `cvar.wait_while`.Taras Tsugrii-5/+2
`wait_while` takes care of spurious wake-ups in centralized place, reducing chances for mistakes and potential future optimizations (who knows, maybe in future there will be no spurious wake-ups? :)
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.