summary refs log tree commit diff
path: root/library/std/src/thread
AgeCommit message (Collapse)AuthorLines
2024-04-11Beta revert "Use OS thread name by default"Chris Denton-20/+0
This reverts #121666 due to #123495 This has already been done on master but beta needs something that will backport cleanly. (cherry picked from commit 081ad8527d7b79e4761c497c12930e630de9a230)
2024-03-07Auto merge of #122113 - matthiaskrgr:rollup-5d1jnwi, r=matthiaskrgrbors-0/+1
Rollup of 9 pull requests Successful merges: - #121958 (Fix redundant import errors for preload extern crate) - #121976 (Add an option to have an external download/bootstrap cache) - #122022 (loongarch: add frecipe and relax target feature) - #122026 (Do not try to format removed files) - #122027 (Uplift some feeding out of `associated_type_for_impl_trait_in_impl` and into queries) - #122063 (Make the lowering of `thir::ExprKind::If` easier to follow) - #122074 (Add missing PartialOrd trait implementation doc for array) - #122082 (remove outdated fixme comment) - #122091 (Note why we're using a new thread in `test_get_os_named_thread`) r? `@ghost` `@rustbot` modify labels: rollup
2024-03-06Document and test minimal stack size on WindowsChris Denton-0/+13
2024-03-06Note why we're using a new thread in a testChris Denton-0/+1
2024-03-04Don't run test_get_os_named_thread on win7roblabla-1/+1
This test won't work on windows 7, as the Thread::set_name function is not implemented there (win7 does not provide a documented mechanism to set thread names).
2024-03-02Rollup merge of #121758 - joboet:move_pal_thread_local, r=ChrisDentonMatthias Krüger-1/+1
Move thread local implementation to `sys` Part of #117276.
2024-02-28std: move thread local implementation to `sys`joboet-1/+1
2024-02-27Test getting the OS thread nameChris Denton-0/+19
2024-02-24Rollup merge of #121530 - wgslr:master, r=Mark-SimulacrumMatthias Krüger-1/+1
Fix incorrect doc of ScopedJoinHandle::is_finished Fixes the explanation how to use `is_finished` to achieve a non-blocking join. The updated version matches the documentation of the non-scoped JoinHandle::is_finished.
2024-02-24Fix incorrect doc of ScopedJoinHandle::is_finishedWojciech Geisler-1/+1
Fixes the explanation how to use is_finished to achieve a non-blocking join. The updated version matches the documentation of the non-scoped JoinHandle::is_finished.
2024-02-23Auto merge of #121303 - GrigorenkoPV:static_mut_refs, r=oli-obk,RalfJungbors-2/+0
Get rid of some `#![allow(static_mut_refs)]`
2024-02-23Get rid of some `#[allow(static_mut_refs)]`Pavel Grigorenko-2/+0
2024-02-23Auto merge of #121454 - reitermarkus:generic-nonzero-library, r=dtolnaybors-3/+3
Use generic `NonZero` everywhere in `library`. Tracking issue: https://github.com/rust-lang/rust/issues/120257 Use generic `NonZero` everywhere (except stable examples). r? `@dtolnay`
2024-02-22Add `rustc_confusables` annotations to some stdlib APIsEsteban Küber-0/+2
Help with common API confusion, like asking for `push` when the data structure really has `append`. ``` error[E0599]: no method named `size` found for struct `Vec<{integer}>` in the current scope --> $DIR/rustc_confusables_std_cases.rs:17:7 | LL | x.size(); | ^^^^ | help: you might have meant to use `len` | LL | x.len(); | ~~~ help: there is a method with a similar name | LL | x.resize(); | ~~~~~~ ``` #59450
2024-02-22Use generic `NonZero` everywhere in `std`.Markus Reiter-3/+3
2024-02-18Improve wording of static_mut_refObei Sideg-2/+2
Rename `static_mut_ref` lint to `static_mut_refs`.
2024-02-15Replace `NonZero::<_>::new` with `NonZero::new`.Markus Reiter-2/+2
2024-02-15Use generic `NonZero` internally.Markus Reiter-5/+4
2024-02-12Auto merge of #110211 - joboet:queue_lock, r=Amanieubors-1/+10
Replace pthread `RwLock` with custom implementation This is one of the last items in #93740. I'm doing `RwLock` first because it is more self-contained and has less tradeoffs to make. The motivation is explained in the documentation, but in short: the pthread rwlock is slow and buggy and `std` can do much better. I considered implementing a parking lot, as was discussed in the tracking issue, but settled for the queue-based version because writing self-balancing binary trees is not fun in Rust... This is a rather complex change, so I have added quite a bit of documentation to help explain it. Please point out any part that could be explained better. ~~The read performance is really good, I'm getting 4x the throughput of the pthread version and about the same performance as usync/parking_lot on an Apple M1 Max in the usync benchmark suite, but the write performance still falls way behind what usync and parking_lot achieve. I tried using a separate queue lock like what usync uses, but that didn't help. I'll try to investigate further in the future, but I wanted to get some eyes on this first.~~ [Resolved](https://github.com/rust-lang/rust/pull/110211#issuecomment-1513682336) r? `@m-ou-se` CC `@kprotty`
2024-02-09adjust code documentationjoboet-2/+2
2024-02-09std: replace pthread `RwLock` with custom implementation inspired by usyncjoboet-1/+10
2024-02-08Step all bootstrap cfgs forwardMark Rousskov-1/+1
This also takes care of other bootstrap-related changes.
2024-01-20Revert example change from PR 116392David Tolnay-4/+1
2024-01-20Allow any expression blocks in `thread_local!`Nikolai Vazquez-3/+6
2024-01-07Update test for `E0796` and `static_mut_ref` lintObei Sideg-0/+2
2024-01-02Update `thread_local` examples to use `local_key_cell_methods`Trevor Gross-18/+32
`local_key_cell_methods` has been stable for a while and provides a much less clunky way to interface with thread-local variables. Additionaly add context to the documentation about why types with interior mutability are needed.
2023-12-07add teeos std impl袁浩-0/+1
Signed-off-by: 袁浩 <yuanhao34@huawei.com>
2023-11-15Bump cfg(bootstrap)sMark Rousskov-4/+0
2023-10-27std::thread: add SAFETY commentRalf Jung-0/+2
2023-10-27replace transmute by raw pointer castRalf Jung-8/+8
2023-09-26std: broaden the allowed behaviour for recursive TLS initializationjoboet-3/+3
2023-09-17Auto merge of #113753 - dvdsk:master, r=dtolnaybors-1/+81
Add implementation for thread::sleep_until - Feature gate is `thread::sleep_until` - Tracking issue is: #113752 - APC: https://github.com/rust-lang/libs-team/issues/237
2023-08-22Replace version placeholders with 1.73.0Mark Rousskov-9/+9
2023-08-10Stabilize thread local cell methods.Mara Bos-18/+9
2023-07-16adds crate attribute to examples so they compiledvdsk-0/+2
2023-07-16fix examples add tracking issuedvdsk-9/+16
2023-07-16fixes sleep_until examplesdvdsk-2/+7
2023-07-15Adds thread::sleep_until, tracking issue TODOdvdsk-0/+66
APC (API change proposal): https://github.com/rust-lang/libs-team/issues/237
2023-06-21Update tvOS support elsewhere in the stdlibThom Chiovoloni-0/+1
2023-06-21Rollup merge of #99587 - ibraheemdev:park-orderings, r=m-ou-seGuillaume Gomez-11/+21
Document memory orderings of `thread::{park, unpark}` Document `thread::park/unpark` as having acquire/release synchronization. Without that guarantee, even the example in the documentation can deadlock: ```rust let flag = Arc::new(AtomicBool::new(false)); let t2 = thread::spawn(move || { while !flag.load(Ordering::Acquire) { thread::park(); } }); flag.store(true, Ordering::Release); t2.thread().unpark(); // t1: flag.store(true) // t1: thread.unpark() // t2: flag.load() == false // t2 now parks, is immediately unblocked but never // acquires the flag, and thus spins forever ``` Multiple calls to `unpark` should also maintain a release sequence to make sure operations released by previous `unpark`s are not lost: ```rust let a = Arc::new(AtomicBool::new(false)); let b = Arc::new(AtomicBool::new(false)); let t2 = thread::spawn(move || { while !a.load(Ordering::Acquire) || !b.load(Ordering::Acquire) { thread::park(); } }); thread::spawn(move || { a.store(true, Ordering::Release); t2.thread().unpark(); }); b.store(true, Ordering::Release); t2.thread().unpark(); // t1: a.store(true) // t1: t2.unpark() // t3: b.store(true) // t3: t2.unpark() // t2 now parks, is immediately unblocked but never // acquires the store of `a`, only the store of `b` which // was released by the most recent unpark, and thus spins forever ``` This is of course a contrived example, but is reasonable to rely upon in real code. Note that all implementations of park/unpark already comply with the rules, it's just undocumented.
2023-06-21"Memory Orderings" -> "Memory Ordering"Mara Bos-1/+1
Co-authored-by: yvt <i@yvt.jp>
2023-06-20relaxed orderings in `thread::park` exampleIbraheem Ahmed-3/+4
2023-06-13Fix typo in mod.rsIkko Eltociear Ashimine-1/+1
assoicated -> associated
2023-06-04Avoid unwind across `extern "C"` in `thread_local::fast_local.rs`Thom Chiovoloni-1/+1
2023-05-15Rollup merge of #110049 - SkiFire13:localkey-with-docs-fix, r=workingjubileeMatthias Krüger-2/+2
Don't claim `LocalKey::with` prevents a reference to be sent across threads The documentation for `LocalKey` claims that `with` yields a reference that cannot be sent across threads, but this is false since you can easily do that with scoped threads. What it actually prevents is the reference from outliving the current thread.
2023-05-10Remove and fix useless drop of referenceUrgau-1/+3
2023-04-28avoid duplicating TLS state between test std and realstdRalf Jung-16/+16
2023-04-27Document `const {}` syntax for `std::thread_local`.Nilstrieb-2/+20
It exists and is pretty cool. More people should use it.
2023-04-26Auto merge of #110861 - m-ou-se:thread-local-restructure, r=workingjubileebors-6/+9
Restructure and rename std thread_local internals to make it less of a maze Every time I try to work on std's thread local internals, it feels like I'm trying to navigate a confusing maze made of macros, deeply nested modules, and types with multiple names/aliases. Time to clean it up a bit. This PR: - Exports `Key` with its own name (`Key`), instead of `__LocalKeyInner` - Uses `pub macro` to put `__thread_local_inner` into a (unstable, hidden) module, removing `#[macro_export]`, removing it from the crate root. - Removes the `__` from `__thread_local_inner`. - Removes a few unnecessary `allow_internal_unstable` features from the macros - Removes the `libstd_thread_internals` feature. (Merged with `thread_local_internals`.) - And removes it from the unstable book - Gets rid of the deeply nested modules for the `Key` definitions (`mod fast` / `mod os` / `mod statik`). - Turns a `#[cfg]` mess into a single `cfg_if`, now that there's no `#[macro_export]` anymore that breaks with `cfg_if`. - Simplifies the `cfg_if` conditions to not repeat the conditions. - Removes useless `normalize-stderr-test`, which were left over from when the `Key` types had different names on different platforms. - Removes a seemingly unnecessary `realstd` re-export on `cfg(test)`. This PR changes nothing about the thread local implementation. That's for a later PR. (Which should hopefully be easier once all this stuff is a bit cleaned up.)
2023-04-26Restructure and rename thread local things in std.Mara Bos-6/+9