about summary refs log tree commit diff
path: root/library/std/src/thread
AgeCommit message (Collapse)AuthorLines
2025-07-29Rollup merge of #144500 - joboet:thread-name-stack-overflow, r=ChrisDentonStuart Cook-1/+1
thread name in stack overflow message Fixes rust-lang/rust#144481, which is caused by the thread name not being initialised yet when setting up the stack overflow information. Unfortunately, the stack overflow UI test did not test for the correct thread name being present, and testing this separately didn't occur to me when writing https://github.com/rust-lang/rust/pull/140628. This PR contains the smallest possible fix I could think of: passing the thread name explicitly to the platform thread creation function. In the future I'd very much like to explore some possibilities around merging the thread packet and thread handle into one structure and using that in the platform code instead – but that's best left for another PR. This PR also amends the stack overflow test to check for thread names, so we don't run into this again. ``@rustbot`` label +beta-nominated
2025-07-28thread name in stack overflow messagejoboet-1/+1
2025-07-26Rollup merge of #143859 - orlp:thread-into-raw-align, r=jhprattTrevor Gross-1/+7
Guarantee 8 bytes of alignment in Thread::into_raw When using `AtomicPtr` for synchronization it's incredibly useful when you've got a couple bits you can stuff metadata in. By guaranteeing that `Thread`'s `Inner` struct is aligned to 8 bytes everyone can use the bottom 3 bits to signal other things, such as a critical section, etc. This guarantee is thus very useful and costs us nothing.
2025-07-15Add LocalKey<Cell>::updateCameron Steffen-0/+23
2025-07-13TidyOrson Peters-1/+1
2025-07-13Guarantee 8 bytes of alignment in Thread::into_rawOrson Peters-1/+7
2025-07-06Auto merge of #141829 - dvdsk:sleep_until_linux, r=cuviper,RalfJungbors-8/+27
Specialize sleep_until implementation for unix (except mac) related tracking issue: https://github.com/rust-lang/rust/issues/113752 Supersedes https://github.com/rust-lang/rust/pull/118480 for the reasons see: https://github.com/rust-lang/rust/issues/113752#issuecomment-2902594469 Replaces the generic catch all implementation with target_os specific ones for: linux/netbsd/freebsd/android/solaris/illumos etc. Other platforms like wasi, macos/ios/tvos/watchos and windows will follow in later separate PR's (once this is merged).
2025-07-06sleep_until: use clock_nanosleep where possibledvdsk-8/+27
Using clock nanosleep leads to more accurate sleep times on platforms where it is supported. To enable using clock_nanosleep this makes `sleep_until` platform specific. That unfortunatly requires identical placeholder implementations for the other platforms (windows/mac/wasm etc). we will land platform specific implementations for those later. See the `sleep_until` tracking issue. This requires an accessors for the Instant type. As that accessor is only used on the platforms that have clock_nanosleep it is marked as allow_unused. 32bit time_t targets do not use clock_nanosleep atm, they instead rely on the same placeholder as the other platforms. We could make them use clock_nanosleep too in the future using `__clock_nanosleep_time64`. __clock_nanosleep_time64 is documented at: https://www.gnu.org/software/libc/manual/html_node/64_002dbit-time-symbol-handling.html
2025-07-03setup CI and tidy to use typos for spellchecking and fix few typosklensy-1/+1
2025-05-12update cfg(bootstrap)Pietro Albini-1/+1
2025-04-27use generic Atomic type where possibleChristopher Durham-11/+11
in core/alloc/std only for now, and ignoring test files Co-authored-by: Pavel Grigorenko <GrigorenkoPV@ya.ru>
2025-04-18LocalKey<T>: document that the dtor should not panicLieselotte-1/+5
2025-04-11rustdoc-search: add unbox flag to Result aliasesMichael Howell-0/+1
Fixes #139665
2025-03-27Auto merge of #138702 - m-ou-se:spawn-in-atexit, r=Mark-Simulacrumbors-9/+14
Allow spawning threads after TLS destruction Fixes #138696
2025-03-19Allow spawning threads after TLS destruction.Mara Bos-9/+14
2025-03-10Mark some std tests as requiring `panic = "unwind"`Paul Menage-0/+5
This allows these test modules to pass on builds/targets without unwinding support, where `panic = "abort"` - the ignored tests are for functionality that's not supported on those targets.
2025-03-06library: Use size_of from the prelude instead of importedThalia Archibald-2/+2
Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the prelude instead of importing or qualifying them. These functions were added to all preludes in Rust 1.80.
2025-02-27Rollup merge of #137480 - fuzzypixelz:fix/124466, r=workingjubileeMatthias Krüger-1/+10
Return unexpected termination error instead of panicing in `Thread::join` There is a time window during which the OS can terminate a thread before stdlib can retreive its `Packet`. Currently the `Thread::join` panics with no message in such an event, which makes debugging difficult; fixes #124466.
2025-02-25Use `.expect(..)` insteadMahmoud Mazouz-5/+10
2025-02-24Remove speculation on cause of errorMahmoud Mazouz-1/+1
Co-authored-by: Jubilee <workingjubilee@gmail.com>
2025-02-23Return error on unexpected termination in `Thread::join`.Mahmoud Mazouz-1/+5
There is a time window during which the OS can terminate a thread before stdlib can retreive its `Packet`. Currently the `Thread::join` panics with no message in such an event, which makes debugging difficult; fixes #124466.
2025-02-21Highlight thread_local! const init in docsKornel-5/+6
2025-01-26Move std::thread_local unit tests to integration testsbjorn3-422/+0
2025-01-21Auto merge of #135224 - wyfo:tls-panic-outline, r=cuviperbors-8/+16
Outline panicking code for `LocalKey::with` See https://github.com/rust-lang/rust/pull/115491 for prior related modifications. https://godbolt.org/z/MTsz87jGj shows a reduction of the code size for TLS accesses.
2025-01-14add comments explaining main thread identificationjoboet-0/+29
2025-01-14std: lazily allocate the main thread handlejoboet-69/+117
Thereby, we also allow accessing thread::current before main: as the runtime no longer tries to install its own handle, this will no longer trigger an abort. Rather, the name returned from name will only be "main" after the runtime initialization code has run, but I think that is acceptable. This new approach also requires some changes to the signal handling code, as calling `thread::current` would now allocate when called on the main thread, which is not acceptable. I fixed this by adding a new function (`with_current_name`) that performs all the naming logic without allocation or without initializing the thread ID (which could allocate on some platforms).
2025-01-14Revert "Remove the Arc rt::init allocation for thread info"joboet-117/+53
This reverts commit 0747f2898e83df7e601189c0f31762e84328becb.
2025-01-08Remove some unnecessary `.into()` callsEsteban Küber-1/+1
2025-01-08Outline panicking code for `LocalKey::with`Joseph Perez-8/+16
See https://github.com/rust-lang/rust/pull/115491 for prior related modifications. https://godbolt.org/z/MTsz87jGj shows a reduction of the code size for TLS accesses.
2024-12-29fix: typoscalciumbe-1/+1
Signed-off-by: calciumbe <192480234+calciumbe@users.noreply.github.com>
2024-12-20mri: add track_caller to thread spawning methods for better backtracesRalf Jung-0/+4
2024-12-06Define acronym for thread local storageWill-Low-1/+1
There are multiple references in this module's documentation to the acronym "TLS", without defining it. This is confusing for the reader. I propose that this acronym be defined during the first use of the term.
2024-12-03Rollup merge of #132937 - xmh0511:master, r=m-ou-seMatthias Krüger-3/+3
a release operation synchronizes with an acquire operation Change: 1. `Calls to park _synchronize-with_ calls to unpark` to `Calls to unpark _synchronize-with_ calls to park` 2. `park synchronizes-with _all_ prior unpark operations` to `_all_ prior unpark operations synchronize-with park`
2024-11-29Auto merge of #133533 - BoxyUwU:bump-boostrap, r=jieyouxu,Mark-Simulacrumbors-1/+0
Bump boostrap compiler to new beta Currently failing due to something about the const stability checks and `panic!`. I'm not sure why though since I wasn't able to see any PRs merged in the past few days that would result in a `cfg(bootstrap)` that shouldn't be removed. cc `@RalfJung` #131349
2024-11-27Rollup merge of #133498 - GuillaumeGomez:missing-examples, r=joboetMatthias Krüger-2/+28
Add missing code examples on `LocalKey` r? ``@Amanieu``
2024-11-27update cfgsBoxy-1/+0
2024-11-26Add missing code examples on `LocalKey`Guillaume Gomez-2/+28
2024-11-25std::thread: avoid leading whitespace in some panic messagesRalf Jung-7/+7
2024-11-25Rollup merge of #132730 - joboet:after_main_sync, r=Noratrieb许杰友 Jieyou Xu (Joe)-6/+33
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-22Fix typo in `std::thread::Scope::spawn` documentation.Colin Finck-1/+1
2024-11-19Update doc comments for spawn hook.Mara Bos-2/+6
2024-11-19Address review comments.Mara Bos-7/+6
Co-authored-by: waffle <waffle.lapkin@gmail.com>
2024-11-19Fix tracking issue.Mara Bos-1/+1
2024-11-19Add tracking issue.Mara Bos-2/+2
2024-11-19Use Send + Sync for spawn hooks.Mara Bos-2/+2
2024-11-19Add thread Builder::no_hooks().Mara Bos-7/+24
2024-11-19Update thread spawn hooks.Mara Bos-35/+84
1. Make the effect thread local. 2. Don't return a io::Result from hooks.
2024-11-19Use add_spawn_hook for libtest's output capturing.Mara Bos-4/+0
2024-11-19Add std::thread::add_spawn_hook.Mara Bos-0/+103
2024-11-18std: allow after-main use of synchronization primitivesjoboet-6/+33
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.