about summary refs log tree commit diff
path: root/library/std/src/sync
AgeCommit message (Collapse)AuthorLines
2025-01-27fix doc for std::sync::mpmcusamoi-4/+12
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.
2024-11-19ignore an occasionally-failing test in MiriRalf Jung-0/+3
2024-11-18std: allow after-main use of synchronization primitivesjoboet-9/+19
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.
2024-11-18Auto merge of #128219 - connortsui20:rwlock-downgrade, r=tgross35bors-4/+175
Rwlock downgrade Tracking Issue: #128203 This PR adds a `downgrade` method for `RwLock` / `RwLockWriteGuard` on all currently supported platforms. Outstanding questions: - [x] ~~Does the `futex.rs` change affect performance at all? It doesn't seem like it will but we can't be certain until we bench it...~~ - [x] ~~Should the SOLID platform implementation [be ported over](https://github.com/rust-lang/rust/pull/128219#discussion_r1693470090) to the `queue.rs` implementation to allow it to support downgrades?~~
2024-11-16reduce threads in downgrade testConnor Tsui-1/+1
2024-11-16fix `DOWNGRADED` bit unpreservedConnor Tsui-1/+1
Co-authored-by: Jonas Böttiger <jonasboettiger@icloud.com>
2024-11-16fix memory ordering bug + bad testConnor Tsui-47/+32
This commit fixes a memory ordering bug in the futex implementation (`Relaxed` -> `Release` on `downgrade`). This commit also removes a badly written test that deadlocked and replaces it with a more reasonable test based on an already-tested `downgrade` test from the parking-lot crate.
2024-11-16add `downgrade` method onto `RwLockWriteGuard`Connor Tsui-4/+70
2024-11-16add `RwLock` `downgrade` testsConnor Tsui-2/+122
2024-11-12Rollup merge of #132869 - ↵Matthias Krüger-0/+4
lolbinarycat:library-fix-too_long_first_doc_paragraph, r=tgross35 split up the first paragraph of doc comments for better summaries used `./x clippy -Aclippy::all '-Wclippy::too_long_first_doc_paragraph' library/core library/alloc` to find these issues.
2024-11-10split up the first paragraph of doc comments for better summariesbinarycat-0/+4
2024-11-07Initialize channel `Block`s directly on the heapJosh Stone-4/+4
The channel's `Block::new` was causing a stack overflow because it held 32 item slots, instantiated on the stack before moving to `Box::new`. The 32x multiplier made modestly-large item sizes untenable. That block is now initialized directly on the heap. Fixes #102246
2024-11-07fix lazylock commentXinye-2/+2
Signed-off-by: Xinye <xinye.tao@metabit-trading.com>
2024-10-26Rollup merge of #132019 - daboross:document-partialeq-oncelock, ↵Matthias Krüger-0/+20
r=Mark-Simulacrum Document `PartialEq` impl for `OnceLock` Adds documentation to `std::sync::OnceLock`'s `PartialEq` implementation: specifies publicly that `OnceLock`s are compared based on their contents, and nothing else. Created in response to, but not directly related to, https://github.com/rust-lang/rust/issues/131959. ## ne This doesn't create and document `PartialEq::ne`. There's precedent for this in [`RefCell`](https://doc.rust-lang.org/std/cell/struct.RefCell.html#impl-PartialEq-for-RefCell%3CT%3E).
2024-10-25library: consistently use American spelling for 'behavior'Ralf Jung-2/+2
2024-10-21Document PartialEq impl for OnceLockDavid Ross-0/+20
2024-10-02mpmc doctest: make sure main thread waits for child threadsRalf Jung-22/+24
2024-10-01Auto merge of #126839 - obeis:mpmc, r=Amanieubors-48/+1729
Add multi-producer, multi-consumer channel (mpmc) Closes #125712 Tracking issue: #126840 r? m-ou-se
2024-09-30Add multi-producer, multi-consumer channel (mpmc)Obei Sideg-48/+1729
2024-09-29Fix std tests for wasm32-wasip2 targetNicola Krumschmidt-20/+23
2024-09-25Use `&raw` in the standard libraryJosh Stone-10/+2
Since the stabilization in #127679 has reached stage0, 1.82-beta, we can start using `&raw` freely, and even the soft-deprecated `ptr::addr_of!` and `ptr::addr_of_mut!` can stop allowing the unstable feature. I intentionally did not change any documentation or tests, but the rest of those macro uses are all now using `&raw const` or `&raw mut` in the standard library.
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-12/+12
2024-09-20Auto merge of #124895 - obeis:static-mut-hidden-ref, r=compiler-errorsbors-0/+3
Disallow hidden references to mutable static Closes #123060 Tracking: - https://github.com/rust-lang/rust/issues/123758
2024-09-18Rollup merge of #130476 - workingjubilee:more-lazy-methods-take-2, r=AmanieuJubilee-6/+142
Implement ACP 429: add `Lazy{Cell,Lock}::get[_mut]` and `force_mut` Tracking issue for `lazy_get`: https://github.com/rust-lang/rust/issues/129333
2024-09-18library: Call it really_init_mut to avoid name collisionsJubilee Young-2/+2
2024-09-18library: Destabilize Lazy{Cell,Lock}::{force,deref}_mutJubilee Young-14/+3
2024-09-17Implement ACP 429: add `Lazy{Cell,Lock}::get[_mut]` and `force_mut`Chayim Refael Friedman-7/+154
In the implementation of `force_mut`, I chose performance over safety. For `LazyLock` this isn't really a choice; the code has to be unsafe. But for `LazyCell`, we can have a full-safe implementation, but it will be a bit less performant, so I went with the unsafe approach.
2024-09-16fix: Remove duplicate `LazyLock` example.Andrew Lilley Brinker-2/+0
The top-level docs for `LazyLock` included two lines of code, each with an accompanying comment, that were identical and with nearly- identical comments. This looks like an oversight from a past edit which was perhaps trying to rewrite an existing example but ended up duplicating rather than replacing, though I haven't gone back through the Git history to check. This commit removes what I personally think is the less-clear of the two examples. Signed-off-by: Andrew Lilley Brinker <alilleybrinker@gmail.com>
2024-09-13Update tests for hidden references to mutable staticObei Sideg-0/+3
2024-09-06Adjust doc comment of Condvar::wait_whileUlrik Mikaelsson-2/+6
The existing phrasing implies that a notification must be received for `wait_while` to return. The phrasing is changed to better reflect the behavior.
2024-09-03Rollup merge of #129885 - cuishuang:master, r=scottmcmMatthias Krüger-1/+1
chore: remove repetitive words
2024-09-02Rollup merge of #129890 - alex:patch-1, r=workingjubileeMatthias Krüger-1/+1
Remove stray word in a comment
2024-09-02Remove stray word in a commentAlex Gaynor-1/+1
2024-09-02Auto merge of #129873 - matthiaskrgr:rollup-bv849ud, r=matthiaskrgrbors-1/+1
Rollup of 9 pull requests Successful merges: - #127474 (doc: Make block of inline Deref methods foldable) - #129678 (Deny imports of `rustc_type_ir::inherent` outside of type ir + new trait solver) - #129738 (`rustc_mir_transform` cleanups) - #129793 (add extra linebreaks so rustdoc can identify the first sentence) - #129804 (Fixed some typos in the standard library documentation/comments) - #129837 (Actually parse stdout json, instead of using hacky contains logic.) - #129842 (Fix LLVM ABI NAME for riscv64imac-unknown-nuttx-elf) - #129843 (Mark myself as on vacation for triagebot) - #129858 (Replace walk with visit so we dont skip outermost expr kind in def collector) Failed merges: - #129777 (Add `unreachable_pub`, round 4) - #129868 (Remove kobzol vacation status) r? `@ghost` `@rustbot` modify labels: rollup
2024-09-02chore: remove repetitive wordscuishuang-1/+1
Signed-off-by: cuishuang <imcusg@gmail.com>
2024-08-31Fixed some typos in the standard library documentation/commentsranger-ross-1/+1
2024-08-14apply #[optimize(size)] to #[cold] ones and part of the panick machineryThe 8472-0/+1
2024-08-08rwlock: disable 'frob' test in Miri on macOSRalf Jung-0/+4
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-08-01Rollup merge of #127567 - joboet:once_wait, r=AmanieuMatthias Krüger-0/+116
std: implement the `once_wait` feature Tracking issue: #127527 This additionally adds a `wait_force` method to `Once` that doesn't panic on poison. I also took the opportunity and cleaned up up the code of the queue-based implementation a bit.
2024-07-31Fix docs for OnceLock::get_mut_or_initJuniper Tyree-3/+3
2024-07-31std: fix busy-waiting in `Once::wait_force`, add more testsjoboet-0/+47