Commit Graph

408 Commits

Author SHA1 Message Date
Jules Bertholet 7f83c784bd Allow passing expr metavariable as a cfg predicate 2026-03-15 13:44:14 -04:00
biscuitrescue 014344b0c3 update panicking() docs for panic=abort
rephrasing and grammar
2026-03-04 01:38:06 +05:30
Jonathan Brouwer faa0d67374 Rollup merge of #149482 - RalfJung:scope-tls-dtors, r=joboet
thread::scope: document how join interacts with TLS destructors

Fixes https://github.com/rust-lang/rust/issues/116237 by documenting the current behavior regarding thread-local destructors as intended. (I'm not stoked about this, but documenting it is better than leaving it unclear.)

This also adds documentation for explicit `join` calls (both for scoped and regular threads), saying that those *will* wait for TLS destructors. That reflects my understanding of the current implementation, which calls `join` on the native thread handle. Are we okay with guaranteeing that? I think we should, so people have at least some chance of implementing "wait for all destructors" manually. This fixes https://github.com/rust-lang/rust/issues/127571.

Cc @rust-lang/libs-api
2026-01-29 17:47:31 +01:00
Leonard Chan 5dbaac1357 Remove Fuchsia from target OS list in unix.rs for sleep 2026-01-27 14:08:15 -08:00
joboet 959be82eff std: implement sleep_until on Apple platforms 2026-01-13 11:22:50 +01:00
Martin Nordholts 8e3d60447c Finish transition from semitransparent to semiopaque for rustc_macro_transparency 2026-01-08 19:14:45 +01:00
Tobias Bucher 440bf4ded9 crate::io::Resultio::Result in most places
I don't know why many places refer to the type as `crate::io::Result`
when `crate::io` is already imported.
2025-12-29 15:09:48 +01:00
joboet 33409da171 std: update references to FromInner etc. 2025-12-15 14:00:37 +01:00
Boxy 85aeb4f259 Forbid object lifetime changing pointer casts 2025-12-10 09:38:56 +00:00
Ralf Jung 14830bfd0c ThreadId generation fallback path: avoid spurious yields 2025-11-30 22:52:28 +01:00
Ralf Jung 1deb487076 thread::scope: document how join interacts with TLS destructors 2025-11-30 14:25:17 +01:00
joboet 9c6e0f6f57 std: update broken links in thread module 2025-11-29 15:59:11 +01:00
joboet 8b08da218e std: split up the thread module 2025-11-29 15:59:11 +01:00
joboet e57df9220a std: split up the thread module (preparation) 2025-11-29 15:12:28 +01:00
Orson Peters b717684f87 Fix SGX implementation 2025-11-28 00:16:30 +01:00
Orson Peters 85a49073c3 Use checked_add instead of manual overflow check 2025-11-28 00:16:30 +01:00
Orson Peters 0b7cdf2435 Address review comments 2025-11-28 00:16:30 +01:00
Orson Peters 58830def36 Ensure set_current is called early during thread init 2025-11-28 00:16:23 +01:00
Orson Peters f9b0811d01 Add documentation guaranteeing global allocator use of TLS
Remove outdated part of comment claiming thread_local re-enters global allocator

Fix typo in doc comment

Add comments for guarantees given and footnote that System may still be called

Revise mention of using the global allocator

Allow for the possibility that the global allocator is the system allocator.

Co-authored-by: Mark Rousskov <mark.simulacrum@gmail.com>
2025-11-28 00:09:12 +01:00
Orson Peters 8481b827fb Use spinlock for ThreadId if 64-bit atomic unavailable 2025-11-28 00:09:12 +01:00
Orson Peters 750609c0a7 Use System allocator for thread-local storage 2025-11-28 00:09:12 +01:00
Evan Jones c4dc39be05 add link to Builder (code review improvement) 2025-10-16 09:07:57 -04:00
Evan Jones 0e2130c2c9 std::thread spawn: Docs: Link to Builder::spawn; Make same.
Replace "use this API instead" with a link to Builder::spawn. Edit
the paragraph to make it slightly clearer.

The Scope::spawn method already included a. Make the docs for the two
nearly the same.
2025-10-08 16:02:31 -04:00
Matthias Krüger 92aac1bdf6 Rollup merge of #146281 - Jules-Bertholet:static-align-thread-local, r=Mark-Simulacrum
Support `#[rustc_align_static]` inside `thread_local!`

Tracking issue: rust-lang/rust#146177

```rust
thread_local! {
    #[rustc_align_static(64)]
    static SO_ALIGNED: u64 = const { 0 };
}
```

This increases the amount of recursion the macro performs (once per attribute in addition to the previous once per item), making it easier to hit the recursion limit. I’ve added workarounds to limit the impact in the case of long doc comments, but this still needs a crater run just in case.

r? libs

``@rustbot`` label A-attributes A-macros A-thread-locals F-static_align T-libs
2025-10-02 10:27:48 +02:00
Josh Simmons cbaec31c10 Add fast-path for accessing the current thread id
Accessing the thread id is often used in profiling and debugging, as
well as some approaches for sound single-threaded access to data.

Currently the only way to access the thread id is by first obtaining a
handle to the current thread. While this is not exactly slow, it does
require an atomic inc-ref and dec-ref operation, as well as the
injection of `Thread`'s drop code into the caller.

This publicly exposes the existing fast-path for accessing the current
thread id.
2025-09-30 20:51:03 +02:00
Jules Bertholet 4d32b9a178 Hoist non-platform-specific code out of thread_local_inner! 2025-09-27 17:05:39 -04:00
Jules Bertholet a4e87e9406 Support #[rustc_align_static] inside thread_local! 2025-09-26 13:51:09 -04:00
Ben Kimock df58fd8cf7 Change the cfg to a dash 2025-09-21 13:12:20 -04:00
Ben Kimock 888679013d Add panic=immediate-abort 2025-09-21 13:12:18 -04:00
Stuart Cook 1037c082bc Rollup merge of #145895 - RalfJung:unpark, r=joboet
thread parking: fix docs and examples

Fixes https://github.com/rust-lang/rust/issues/145816

r? ```@joboet```
Cc ```@m-ou-se``` ```@Amanieu```
2025-09-12 20:02:10 +10:00
joboet ad08577a50 std: move thread into sys 2025-09-10 15:26:17 +02:00
Ralf Jung 39d51d04e7 thread parking: fix docs and examples 2025-09-03 09:14:25 +02:00
Quinn Tucker e84d29284c Tweak wording again 2025-08-19 19:05:19 -04:00
Quinn Tucker 14022c8a9a Adjust wording for conciseness 2025-08-19 17:14:26 -04:00
Quinn Tucker d0841c7dec Fix typos in LocalKey documentation 2025-08-19 16:47:25 -04:00
Josh Triplett 1ae4a0cc34 library: Migrate from cfg_if to cfg_select
Migrate the standard library from using the external `cfg_if` crate to
using the now-built-in `cfg_select` macro.

This does not yet eliminate the dependency from
`library/std/Cargo.toml`, because while the standard library itself no
longer uses `cfg_if`, it also incorporates the `backtrace` crate, which
does.

Migration assisted by the following vim command (after selecting the
full `cfg_if!` invocation):

```
'<,'>s/\(cfg_if::\)\?cfg_if/cfg_select/ | '<,'>s/^\( *\)} else {/\1}\r\1_ => {/c | '<,'>s/^\( *\)} else if #\[cfg(\(.*\))\] /\1}\r\1\2 => /e | '<,'>s/if #\[cfg(\(.*\))\] {/\1 => {/e
```

This is imperfect, but substantially accelerated the process. This
prompts for confirmation on the `} else {` since that can also appear
inside one of the arms. This also requires manual intervention to handle
any multi-line conditions.
2025-08-16 05:28:31 -07:00
Trevor Gross 289fe36d37 Print thread ID in panic message if thread name is unknown
`panic!` does not print any identifying information for threads that are
unnamed. However, in many cases, the thread ID can be determined.

This changes the panic message from something like this:

    thread '<unnamed>' panicked at src/main.rs:3:5:
    explicit panic

To something like this:

    thread '<unnamed>' (0xff9bf) panicked at src/main.rs:3:5:
    explicit panic

Stack overflow messages are updated as well.

This change applies to both named and unnamed threads. The ID printed is
the OS integer thread ID rather than the Rust thread ID, which should
also be what debuggers print.
2025-08-06 23:59:47 +00:00
Stuart Cook e65201ccb8 Rollup merge of #144188 - joshtriplett:available-parallelism, r=Mark-Simulacrum
`available_parallelism`: Add documentation for why we don't look at `ulimit`
2025-08-04 11:24:36 +10:00
Stuart Cook 4bfbd80bab Rollup merge of #144500 - joboet:thread-name-stack-overflow, r=ChrisDenton
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-29 20:19:51 +10:00
joboet 73751a0491 thread name in stack overflow message 2025-07-28 18:09:35 +02:00
Trevor Gross 2fcea9fb68 Rollup merge of #143859 - orlp:thread-into-raw-align, r=jhpratt
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-26 02:19:29 -05:00
Josh Triplett 41199f39d8 available_parallelism: Add documentation for why we don't look at ulimit 2025-07-19 11:17:38 -07:00
Cameron Steffen 1120cb2fe5 Add LocalKey<Cell>::update 2025-07-15 16:17:57 -05:00
Orson Peters 6f4d0bdde8 Tidy 2025-07-13 01:20:29 +02:00
Orson Peters 69b9bae57d Guarantee 8 bytes of alignment in Thread::into_raw 2025-07-13 00:58:46 +02:00
bors ca98d4d4b3 Auto merge of #141829 - dvdsk:sleep_until_linux, r=cuviper,RalfJung
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-06 23:00:51 +00:00
dvdsk f24ee2c9b1 sleep_until: use clock_nanosleep where possible
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-06 17:36:49 +02:00
klensy c76d032f01 setup CI and tidy to use typos for spellchecking and fix few typos 2025-07-03 10:51:06 +03:00
Pietro Albini 2ce08ca5d6 update cfg(bootstrap) 2025-05-12 15:33:37 +02:00
Christopher Durham 4d93f60568 use generic Atomic type where possible
in core/alloc/std only for now, and ignoring test files

Co-authored-by: Pavel Grigorenko <GrigorenkoPV@ya.ru>
2025-04-27 02:18:08 +03:00