about summary refs log tree commit diff
path: root/library/std/src/sync
AgeCommit message (Collapse)AuthorLines
2024-04-22remove an unused type from the reentrant lock testsRalf Jung-8/+1
2024-04-06Rollup merge of #114788 - tisonkun:get_mut_or_init, r=dtolnayMatthias Krüger-0/+81
impl get_mut_or_init and get_mut_or_try_init for OnceCell and OnceLock See also https://github.com/rust-lang/rust/issues/74465#issuecomment-1676522051 I'm trying to understand the process for such proposal. And I'll appreciate it if anyone can guide me the next step for consensus or adding tests.
2024-03-27impl get_mut_or_init and get_mut_or_try_init for OnceCell and OnceLocktison-0/+81
See also https://github.com/rust-lang/rust/issues/74465#issuecomment-1676522051 Signed-off-by: tison <wander4096@gmail.com>
2024-03-26Update `RwLock` deadlock example to not use shadowingTrevor Gross-6/+7
Tweak variable names in the deadlock example to remove any potential confusion that the behavior is somehow shadowing-related.
2024-03-22docs(sync): normalize dot in fn summariesMultisampledNight-2/+2
2024-03-20Rollup merge of #122729 - m-ou-se:relax, r=AmanieuJacob Pratt-2/+2
Relax SeqCst ordering in standard library. Every single SeqCst in the standard library is unnecessary. In all cases, Relaxed or Release+Acquire was sufficient. As I [wrote](https://marabos.nl/atomics/memory-ordering.html#common-misconceptions) in my book on atomics: > [..] when reading code, SeqCst basically tells the reader: "this operation depends on the total order of every single SeqCst operation in the program," which is an incredibly far-reaching claim. The same code would likely be easier to review and verify if it used weaker memory ordering instead, if possible. For example, Release effectively tells the reader: "this relates to an acquire operation on the same variable," which involves far fewer considerations when forming an understanding of the code. > > It is advisable to see SeqCst as a warning sign. Seeing it in the wild often means that either something complicated is going on, or simply that the author did not take the time to analyze their memory ordering related assumptions, both of which are reasons for extra scrutiny. r? ````@Amanieu```` ````@joboet````
2024-03-20SeqCst->Relaxed in condvar test.Mara Bos-2/+2
Relaxed is enough here. Synchronization is done by the mutex.
2024-03-19branch 1.78: replace-version-placeholderMark Rousskov-1/+1
2024-03-13Rollup merge of #122386 - joboet:move_pal_once, r=jhprattMatthias Krüger-5/+5
Move `Once` implementations to `sys` Part of https://github.com/rust-lang/rust/issues/117276.
2024-03-12std: move `Once` implementations to `sys`joboet-5/+5
2024-03-12Use `min_exhaustive_patterns` in core & stdNadrieril-0/+8
2024-03-01Rollup merge of #121736 - HTGAzureX1212:HTGAzureX1212/remove-mutex-unlock, ↵Matthias Krüger-20/+0
r=jhpratt Remove `Mutex::unlock` Function As of the completion of the FCP in https://github.com/rust-lang/rust/issues/81872#issuecomment-1474104525, it has come to the conclusion to be closed. This PR removes the function entirely in light of the above. Closes #81872.
2024-02-29fix typosIbraheem Ahmed-3/+3
Co-authored-by: Ralf Jung <post@ralfj.de>
2024-02-29document potential memory leak in unbounded channelIbraheem Ahmed-0/+3
2024-02-29Rollup merge of #110543 - joboet:reentrant_lock, r=m-ou-seMatthias Krüger-197/+340
Make `ReentrantLock` public Implements the ACP rust-lang/libs-team#193. ``@rustbot`` label +T-libs-api +S-waiting-on-ACP
2024-02-28remove Mutex::unlockHTGAzureX1212.-20/+0
2024-02-26fix race between block initialization and receiver disconnectionIbraheem Ahmed-2/+2
2024-02-25Auto merge of #117107 - zachs18:mapped-mutex-guard, r=Amanieubors-4/+985
Implement `MappedMutexGuard`, `MappedRwLockReadGuard`, and `MappedRwLockWriteGuard`. ACP: https://github.com/rust-lang/libs-team/issues/260 Tracking issue: https://github.com/rust-lang/rust/issues/117108 <details> <summary> (Outdated) </summary> `MutexState`/`RwLockState` structs ~~Having `sys::(Mutex|RwLock)` and `poison::Flag` as separate fields in the `Mutex`/`RwLock` would require `MappedMutexGuard`/`MappedRwLockWriteGuard` to hold an additional pointer, so I combined the two fields into a `MutexState`/`RwLockState` struct. This should not noticeably affect perf or layout, but requires an additional field projection when accessing the former `.inner` or `.poison` fields (now `.state.inner` and `.state.poison`).~~ If this is not desired, then `MappedMutexGuard`/`MappedRwLockWriteGuard` can instead hold separate pointers to the two fields. </details> The doc-comments are mostly copied from the existing `*Guard` doc-comments, with some parts from `lock_api::Mapped*Guard`'s doc-comments. Unresolved question: Are more tests needed?
2024-02-24library: use `addr_of!`Pavel Grigorenko-2/+6
2024-02-23Apply suggestions from code reviewzachs18-3/+3
Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
2024-02-23Auto merge of #119536 - Jules-Bertholet:const-barrier, r=dtolnaybors-1/+3
Make `Barrier::new()` const I guess this was just missed in #97791? `@rustbot` label T-libs-api -T-libs
2024-02-23std: make `ReentrantLock` publicjoboet-197/+340
2024-02-14Auto merge of #121078 - oli-obk:rollup-p11zsav, r=oli-obkbors-1/+1
Rollup of 13 pull requests Successful merges: - #116387 (Additional doc links and explanation of `Wake`.) - #118738 (Netbsd10 update) - #118890 (Clarify the lifetimes of allocations returned by the `Allocator` trait) - #120498 (Uplift `TypeVisitableExt` into `rustc_type_ir`) - #120530 (Be less confident when `dyn` suggestion is not checked for object safety) - #120915 (Fix suggestion span for `?Sized` when param type has default) - #121015 (Optimize `delayed_bug` handling.) - #121024 (implement `Default` for `AsciiChar`) - #121039 (Correctly compute adjustment casts in GVN) - #121045 (Fix two UI tests with incorrect directive / invalid revision) - #121049 (Do not point at `#[allow(_)]` as the reason for compat lint triggering) - #121071 (Use fewer delayed bugs.) - #121073 (Fix typos in `OneLock` doc) r? `@ghost` `@rustbot` modify labels: rollup
2024-02-14Auto merge of #100603 - tmandry:zst-guards, r=dtolnaybors-2/+49
Optimize away poison guards when std is built with panic=abort > **Note**: To take advantage of this PR, you will have to use `-Zbuild-std` or build your own toolchain. rustup toolchains always link to a libstd that was compiled with `panic=unwind`, since it's compatible with `panic=abort` code. When std is compiled with `panic=abort` we can remove a lot of the poison machinery from the locks. This changes the `Flag` and `Guard` types to be ZSTs. It also adds an uninhabited member to `PoisonError` so the compiler knows it can optimize away the `Result::Err` paths, and make `LockResult<T>` layout-equivalent to `T`. ### Is this a breaking change? `PoisonError::new` now panics if invoked from a libstd built with `panic="abort"` (or any non-`unwind` strategy). It is unclear to me whether to consider this a breaking change. In order to encounter this behavior, **both of the following must be true**: #### Using a libstd with `panic="abort"` This is pretty uncommon. We don't build libstd with that in rustup, except in (Tier 2-3) platforms that do not support unwinding, **most notably wasm**. Most people who do this are using cargo's `-Z build-std` feature, which is unstable. `panic="abort"` is not a supported option in Rust's build system. It is possible to configure it using `CARGO_TARGET_xxx_RUSTFLAGS`, but I believe this only works on **non-host** platforms. #### Creating `PoisonError` manually This is also unlikely. The only common use case I can think of is in tests, and you can't run tests with `panic="abort"` without the unstable `-Z panic_abort_tests` flag. It's possible that someone is implementing their own locks using std's `PoisonError` **and** defining "thread failure" to mean something other than "panic". If this is the case then we would break their code if it was used with a `panic="abort"` libstd. The locking crates I know of don't replicate std's poison API, but I haven't done much research into this yet. I've touched on a fair number of considerations here. Which ones do people consider relevant?
2024-02-14Fix typos in `OneLock` docIgor-1/+1
2024-02-08Bump version placeholdersMark Rousskov-2/+2
2024-01-14std: Doc blocking behavior of LazyLock methodsBehnam Esfahbod-6/+15
2024-01-10Stabilize mutex_unpoison featureThayne McCombs-6/+2
Closes #96469 @rustbot +T-libs-api
2024-01-02Make `Barrier::new()` constJules Bertholet-1/+3
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-12-05fmtZachary S-4/+1
2023-12-05Specify behavior if the closure passed to *Guard::*map panics.Zachary S-69/+364
2023-12-05fix MappedMutexGuard::(try_)map doc typo.Zachary S-2/+2
2023-12-05Add MappedMutexGuard and MappedRwLock*Guard tests.Zachary S-2/+133
2023-12-05Fix Condvar typo, add public re-exports of Mapped*Guard.Zachary S-2/+6
2023-12-05Add comment about `Mapped(Mutex|RwLockWrite)Guard` variance.Zachary S-35/+43
2023-12-05Implmement `MappedRwLock(Read|Write)Guard`.Zachary S-3/+355
2023-12-05Implement `MappedMutexGuard`.Zachary S-0/+193
2023-12-05Allow cloning `poison::Guard`s.Zachary S-0/+1
(makes implementing `Mapped*Guard` easier)
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? :)