about summary refs log tree commit diff
path: root/library/std/src/sync/once_lock.rs
AgeCommit message (Collapse)AuthorLines
2025-07-19Document guarantees of poisoningAlisa Sireneva-0/+2
This mostly documents the current behavior of `Mutex` and `RwLock` as imperfect. It's unlikely that the situation improves significantly in the future, and even if it does, the rules will probably be more complicated than "poisoning is completely reliable", so this is a conservative guarantee. We also explicitly specify that `OnceLock` never poisons, even though it has an API similar to mutexes.
2025-05-28Clarify &mut-methods' docs on sync::OnceLockLukas Lueg-5/+13
2025-05-08Update documentation of OnceLock::get_or_init.Luca Versari-1/+1
Explicitly point out that if the function panics the init function might be called multiple times.
2025-02-18update version placeholdersJosh Stone-1/+1
(cherry picked from commit e4840ce59bdddb19394df008c5c26d9c493725f8)
2025-02-04Rollup merge of #135621 - bjorn3:move_tests_to_stdtests, r=NoratriebJacob Pratt-3/+0
Move some std tests to integration tests Unit tests directly inside of standard library crates require a very fragile way of building that is hard to reproduce outside of bootstrap. Follow up to https://github.com/rust-lang/rust/pull/133859
2025-02-03Rollup merge of #136289 - Pyr0de:oncecell-docs, r=tgross35Matthias Krüger-29/+36
OnceCell & OnceLock docs: Using (un)initialized consistently Changed * `set` / `initialize` / `full` to `initialized state` * `uninitialize` / `empty` to `uninitialized state` * `f` to `f()` * Added explaination of `uninitialized state` & `initialized state` [OnceCell Docs](https://doc.rust-lang.org/nightly/std/cell/struct.OnceCell.html) [OnceLock Docs](https://doc.rust-lang.org/nightly/std/sync/struct.OnceLock.html) Fixes #85716 ``@rustbot`` label +A-docs
2025-02-03OnceCell & OnceLock docs: Using (un)initialized consistentlyPyrode-29/+36
2025-02-01stabilize `once_wait`Slanterns-3/+1
2025-01-26Move std::sync unit tests to integration testsbjorn3-3/+0
This removes two minor OnceLock tests which test private methods. The rest of the tests should be more than enough to catch mistakes in those private methods. Also makes ReentrantLock::try_lock public. And finally it makes the mpmc tests actually run.
2025-01-02Move some things to `std::sync::poison` and reexport them in `std::sync`Pavel Grigorenko-0/+1
2024-10-21Document PartialEq impl for OnceLockDavid Ross-0/+20
2024-09-02Remove stray word in a commentAlex Gaynor-1/+1
2024-08-14apply #[optimize(size)] to #[cold] ones and part of the panick machineryThe 8472-0/+1
2024-08-01Auto merge of #128461 - matthiaskrgr:rollup-3dpp11g, r=matthiaskrgrbors-3/+3
Rollup of 7 pull requests Successful merges: - #123813 (Add `REDUNDANT_IMPORTS` lint for new redundant import detection) - #126697 ([RFC] mbe: consider the `_` in 2024 an expression) - #127159 (match lowering: Hide `Candidate` from outside the lowering algorithm) - #128244 (Peel off explicit (or implicit) deref before suggesting clone on move error in borrowck, remove some hacks) - #128431 (Add myself as VxWorks target maintainer for reference) - #128438 (Add special-case for [T, 0] in dropck_outlives) - #128457 (Fix docs for OnceLock::get_mut_or_init) r? `@ghost` `@rustbot` modify labels: rollup
2024-07-31Fix docs for OnceLock::get_mut_or_initJuniper Tyree-3/+3
2024-07-31std: implement the `once_wait` featurejoboet-0/+28
2024-07-26Fix doc nitsJohn Arundel-1/+1
Many tiny changes to stdlib doc comments to make them consistent (for example "Returns foo", rather than "Return foo", per RFC1574), adding missing periods, paragraph breaks, backticks for monospace style, and other minor nits. https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
2024-07-14std: Unsafe-wrap std::syncJubilee Young-2/+2
2024-07-07once_lock: make test not take as long in MiriRalf Jung-6/+13
2024-06-04Rollup merge of #125696 - workingjubilee:please-dont-say-you-are-lazy, ↵Guillaume Gomez-36/+55
r=Nilstrieb Explain differences between `{Once,Lazy}{Cell,Lock}` types The question of "which once-ish cell-ish type should I use?" has been raised multiple times, and is especially important now that we have stabilized the `LazyCell` and `LazyLock` types. The answer for the `Lazy*` types is that you would be better off using them if you want to use what is by far the most common pattern: initialize it with a single nullary function that you would call at every `get_or_init` site. For everything else there's the `Once*` types. "For everything else" is a somewhat weak motivation, as it only describes by negation. While contrasting them is inevitable, I feel positive motivations are more understandable. For this, I now offer a distinct example that helps explain why `OnceLock` can be useful, despite `LazyLock` existing: you can do some cool stuff with it that `LazyLock` simply can't support due to its mere definition. The pair of `std::sync::*Lock`s are usable inside a `static`, and can serve roles in async or multithreaded (or asynchronously multithreaded) programs that `*Cell`s cannot. Because of this, they received most of my attention. Fixes #124696 Fixes #125615
2024-06-02Add "OnceList" example to motivate OnceLockJubilee Young-0/+55
While slightly verbose, it helps explain "why bother with OnceLock?" This is a point of confusion that has been raised multiple times shortly before and after the stabilization of LazyLock.
2024-06-02Move first OnceLock example to LazyLockJubilee Young-36/+0
This example is spiritually an example of LazyLock, as it computes a variable at runtime but accepts no inputs into that process. It is also slightly simpler and thus easier to understand. Change it to an even-more concise version and move it to LazyLock. The example now editorializes slightly more. This may be unnecessary, but it can be educational for the reader.
2024-05-24Change pedantically incorrect OnceCell/OnceLock wordingMahmoud Al-Qudsi-1/+1
While the semantic intent of a OnceCell/OnceLock is that it can only be written to once (upon init), the fact of the matter is that both these types offer a `take(&mut self) -> Option<T>` mechanism that, when successful, resets the cell to its initial state, thereby technically allowing it to be written to again. Despite the fact that this can only happen with a mutable reference (generally only used during the construction of the OnceCell/OnceLock), it would be incorrect to say that the type itself as a whole categorically prevents being initialized or written to more than once (since it is possible to imagine an identical type only without the `take()` method that actually fulfills that contract). To clarify, change "that cannot be.." to "that nominally cannot.." and add a note to OnceCell about what can be done with an `&mut Self` reference.
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-02-14Fix typos in `OneLock` docIgor-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-13Implement `OnceCell/Lock::try_insert()`daxpedda-3/+40
2023-07-31Rollup merge of #109318 - joboet:better_fmt_placeholder, r=dtolnayMatthias Krüger-3/+5
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-04-28replace version placeholdersPietro Albini-20/+20
2023-04-19std: make `Debug` representations of `[Lazy, Once]*[Cell, Lock]` consistent ↵joboet-3/+5
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-03-29Stabilize a portion of 'once_cell'Trevor Gross-37/+22
Move items not part of this stabilization to 'lazy_cell' or 'once_cell_try'
2022-12-13Add #[inline] marker to OnceCell/LazyCell/OnceLock/LazyLockTrevor Gross-1/+16
2022-11-17Properly link `{Once,Lazy}{Cell,Lock}` in docsMaybe Waffle-2/+4
2022-09-03std: make `ReentrantMutex` movable and `const`; simplify `Stdout` initializationjoboet-55/+0
2022-06-16Move/rename `lazy::Sync{OnceCell,Lazy}` to `sync::{Once,Lazy}Lock`Maybe Waffle-0/+496