about summary refs log tree commit diff
path: root/library/std/src/sync
AgeCommit message (Collapse)AuthorLines
2025-07-29add `nonpoison::mutex` implementationConnor Tsui-0/+650
Adds the equivalent `nonpoison` types to the `poison::mutex` module. These types and implementations are gated under the `nonpoison_mutex` feature gate. Also blesses the ui tests that now have a name conflicts (because these types no longer have unique names). The full path distinguishes the different types. Co-authored-by: Aandreba <aandreba@gmail.com> Co-authored-by: Trevor Gross <tmgross@umich.edu>
2025-07-29clean up existing poison filesConnor Tsui-5/+5
2025-07-15Update poison.rsMartin Ombura Jr.-1/+1
Typo in word "below"
2025-07-07Rollup merge of #143340 - nabijaczleweli:awhile, r=mati865Matthias Krüger-2/+2
awhile -> a while where appropriate
2025-07-04Rollup merge of #143086 - SciMind2460:patch-2, r=workingjubileeJubilee-1/+1
Update poison.rs to fix the typo (sys->sync)
2025-07-02awhile -> a while where appropriateнаб-2/+2
2025-07-01Update version placeholdersJosh Stone-1/+1
2025-06-27Update poison.rs to fix the typo (sys->sync)Kurt Heiritz (pseudo)-1/+1
2025-06-26Fix RwLock::try_write documentation for WouldBlock conditionkrikera-1/+1
2025-06-03Rollup merge of #140715 - lukaslueg:oncecellsyncdocs, r=tgross35Matthias Krüger-5/+13
Clarify &mut-methods' docs on sync::OnceLock Three small changes to the docs of `sync::OnceLock`: * The docs for `OnceLock::take()` used to [say](https://doc.rust-lang.org/std/sync/struct.OnceLock.html#method.take) "**Safety** is guaranteed by requiring a mutable reference." (emphasis mine). While technically correct, imho its not necessary to even mention safety - as opposed to unsafety - here: Safety never comes up wrt `OnceLock`, as there is (currently) no way to interact with a `OnceLock` in an unsafe way; there are no unsafe methods on `OnceLock`, so there is "safety" guarantee required anywhere. What we simply meant to say is "**Synchronization** is guaranteed...". * I've add that phrase to the other methods of `OnceLock` which take a `&mut self`, to highlight the fact that having a `&mut OnceLock` guarantees that synchronization with other threads is not required. This is the same as with [`Mutex::get_mut()`](https://doc.rust-lang.org/std/sync/struct.Mutex.html#method.get_mut), [`Cell::get_mut()`](https://doc.rust-lang.org/std/cell/struct.Cell.html#method.get_mut), and others. * In that spirit, the half-sentence "or being initialized" was removed from `get_mut()`, as there is no way that the `OnceLock` is being initialized while we are holding `&mut` to it. Probably a copy&paste from `.get()`
2025-05-28Clarify &mut-methods' docs on sync::OnceLockLukas Lueg-5/+13
2025-05-28Rollup merge of #140369 - jplatte:mutex-rwlock-data-ptr, r=AmanieuTrevor Gross-0/+33
Add data_ptr method to Mutex and RwLock Implementation of https://github.com/rust-lang/rust/issues/140368 / https://github.com/rust-lang/libs-team/issues/531. I tried to write a useful safety section about when it is safe to read or write through the returned pointers, but couldn't come up with something nice. Hoping this PR is still useful without that. I'm happy to add any doc strings other people come up with if needed before merge, of course. Unresolved questions: - Return a `LockResult` or not? - Return `*mut T` like existing APIs (`Cell::as_ptr` / `MaybeUninit::as[_mut]_ptr` / `Vec::as_ptr` / ...) or be more precise and return `NonNull<T>`?
2025-05-22docs: fix typosDannyyy93-1/+1
2025-05-21Add ReentrantLock::data_ptrJonas Platte-0/+11
2025-05-21Add more docs to new data_ptr methodsJonas Platte-0/+10
2025-05-21Add data_ptr method to Mutex and RwLockJonas Platte-0/+12
2025-05-19fix data race in ReentrantLock fallback for targets without 64bit atomicsRalf Jung-2/+6
2025-05-10Rollup merge of #140783 - veluca93:oncelock-docs, r=jhprattMatthias Krüger-1/+1
Update documentation of OnceLock::get_or_init. Explicitly point out that if the function panics the init function might be called multiple times.
2025-05-10Rollup merge of #129334 - ChayimFriedman2:more-lazy-methods, r=AmanieuMatthias Krüger-1/+9
Implement (part of) ACP 429: add `DerefMut` to `Lazy[Cell/Lock]` `DerefMut` is instantly stable, as a trait impl. That means this needs an FCP. ``@rustbot`` label +needs-fcp https://github.com/rust-lang/libs-team/issues/429
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-04-30Rename `(Mapped)(RwLock|Mutex)Guard::try_map` to `filter_map`.Zachary S-41/+35
1. analogous to std::cell::Ref(Mut)::filter_map. 2. doesn't imply `Try` genericizability.
2025-04-27use generic Atomic type where possibleChristopher Durham-27/+28
in core/alloc/std only for now, and ignoring test files Co-authored-by: Pavel Grigorenko <GrigorenkoPV@ya.ru>
2025-04-18Rollup merge of #139553 - petrosagg:channel-double-free, r=RalfJung,tgross35Matthias Krüger-1/+12
sync::mpsc: prevent double free on `Drop` This PR is fixing a regression introduced by #121646 that can lead to a double free when dropping the channel. The details of the bug can be found in the corresponding crossbeam PR https://github.com/crossbeam-rs/crossbeam/pull/1187
2025-04-11sync::mpsc: prevent double free on `Drop`Petros Angelatos-1/+7
This PR is fixing a regression introduced by #121646 that can lead to a double free when dropping the channel. The details of the bug can be found in the corresponding crossbeam PR https://github.com/crossbeam-rs/crossbeam/pull/1187 Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
2025-04-11sync::mpsc: add miri reproducer of double freePetros Angelatos-0/+5
Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
2025-04-09Rollup merge of #139164 - xizheyin:issue-139034, r=joboetMatthias Krüger-2/+8
std: improve documentation for get_mut() methods regarding forgotten guards Fixes #139034 This PR improves the documentation for `get_mut()` methods in `Mutex`, `RefCell`, and `RwLock` to clarify their behavior when lock guards are forgotten (e.g., via std::mem::forget). The current documentation for these methods states that a mutable borrow "statically guarantees no locks exist", which is not entirely accurate. While a mutable borrow prevents new locks from being created, it does not clear or detect previously abandoned locks through `forget()`. This can lead to counterintuitive behavior: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=e68cefec12dcd435daf2237c16824ed3 https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=81263ad652c752afd63c903113d3082c https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=311baa4edb3abf82a25c8d7bf21a4a52 r? libs
2025-04-03std: clarify RwLock::get_mut more clearlyxizheyin-1/+3
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-03-31std: clarify Mutex::get_mut more clearlyxizheyin-1/+5
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-03-22Implement `UniqueArc`Frank King-0/+2
2025-02-23Auto merge of #137237 - cuviper:stage0, r=Mark-Simulacrumbors-3/+3
Master bootstrap update https://forge.rust-lang.org/release/process.html#master-bootstrap-update-tuesday r? `@Mark-Simulacrum`
2025-02-21Use faster thread_local in current_thread_id()Kornel-1/+18
2025-02-18update version placeholdersJosh Stone-3/+3
(cherry picked from commit e4840ce59bdddb19394df008c5c26d9c493725f8)
2025-02-09Fix pattern matching mode changes and unsafe_op_in_unsafe_fnMichael Goulet-3/+3
2025-02-04Rollup merge of #135621 - bjorn3:move_tests_to_stdtests, r=NoratriebJacob Pratt-4130/+8
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-01Rollup merge of #136360 - slanterns:once_wait, r=tgross35Matthias Krüger-7/+3
Stabilize `once_wait` Closes: https://github.com/rust-lang/rust/issues/127527. `@rustbot` label: +T-libs-api r? libs-api
2025-02-01Rollup merge of #135684 - ranger-ross:mutex-docs, r=joboetMatthias Krüger-2/+30
docs: Documented Send and Sync requirements for Mutex + MutexGuard This an attempt to continue where #123225 left off. I did some light clean up from the work done in that PR. I also documented the `!Send` + `Sync` implementations for `MutexGuard` to the best of my knowledge. Let me know if I got anything wrong :smile: fixes #122856 cc: ``@IoaNNUwU`` r? ``@joboet``
2025-02-01docs: Documented Send and Sync requirements for Mutex + MutexGuardRoss Sullivan-2/+30
2025-02-01stabilize `once_wait`Slanterns-7/+3
2025-01-27fix doc for std::sync::mpmcusamoi-4/+12
2025-01-26Move std::sync unit tests to integration testsbjorn3-4130/+8
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-15Clarify note in `std::sync::LazyLock` exampleAeon-1/+1
2025-01-06chore: remove redundant words in commentcrystalstall-1/+1
Signed-off-by: crystalstall <crystalruby@qq.com>
2025-01-02Move some things to `std::sync::poison` and reexport them in `std::sync`Pavel Grigorenko-24/+128
2024-12-24Use scoped threads in `std::sync::Barrier` examplesdeltragon-34/+26
This removes boilerplate around `Arc`s and makes the code more clear.
2024-11-30Add value accessor methods to `Mutex` and `RwLock`EFanZh-86/+517
2024-11-26Rollup merge of #133435 - RalfJung:test_downgrade_observe, r=tgross35Michael Goulet-1/+4
miri: disable test_downgrade_observe test on macOS Due to https://github.com/rust-lang/rust/issues/121950, this test can fail on Miri. The test is also quite slow on Miri (taking more than 30s) due to the high iteration count (a total of 2000), so let's reduce that a little. Fixes https://github.com/rust-lang/rust/issues/133421
2024-11-25miri: disable test_downgrade_observe test on macOSRalf Jung-1/+4
2024-11-25Rollup merge of #132730 - joboet:after_main_sync, r=Noratrieb许杰友 Jieyou Xu (Joe)-9/+19
std: allow after-main use of synchronization primitives By creating an unnamed thread handle when the actual one has already been destroyed, synchronization primitives using thread parking can be used even outside the Rust runtime. This also fixes an inefficiency in the queue-based `RwLock`: if `thread::current` was not initialized yet, it will create a new handle on every parking attempt without initializing `thread::current`. The private `current_or_unnamed` function introduced here fixes this.