rust/library/std/src/sys
Guillaume Gomez 4c26dc5d3d
Rollup merge of #132654 - joboet:lazy_main, r=ChrisDenton
std: lazily allocate the main thread handle

https://github.com/rust-lang/rust/pull/123550 eliminated the allocation of the main thread handle, but at the cost of greatly increased complexity. This PR proposes another approach: Instead of creating the main thread handle itself, the runtime simply remembers the thread ID of the main thread. The main thread handle is then only allocated when it is used, using the same lazy-initialization mechanism as for non-runtime use of `thread::current`, and the `name` method uses the thread ID to identify the main thread handle and return the correct name ("main") for it.

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).

Reverts #123550, CC ``@GnomedDev``
2025-01-15 16:30:08 +01:00
..
alloc Revert using HEAP static in Windows alloc 2024-10-18 11:11:38 +00:00
anonymous_pipe Remove unneeded pub(crate) 2024-07-31 13:45:14 +00:00
os_str Make CloneToUninit dyn-compatible 2024-11-12 15:08:41 -06:00
pal Rollup merge of #132654 - joboet:lazy_main, r=ChrisDenton 2025-01-15 16:30:08 +01:00
path path: Move is_absolute check to sys::path 2025-01-13 11:52:03 +05:30
personality Rollup merge of #133420 - thesummer:rtems-unwind, r=workingjubilee 2025-01-03 22:12:41 +01:00
random Use arc4random of libc for RTEMS target 2024-11-21 23:10:19 +01:00
sync Rollup merge of #134389 - rust-wasi-web:condvar-no-threads, r=m-ou-se 2025-01-08 00:52:45 -05:00
thread_local Rollup merge of #133472 - rust-wasi-web:master, r=joboet 2024-12-10 08:55:57 +01:00
backtrace.rs Improve comments for the default backtrace printer 2024-12-04 20:54:37 -05:00
cmath.rs fmt 2024-11-27 12:02:02 -05:00
exit_guard.rs Attempt to fix CI 2024-07-08 09:19:25 -05:00
mod.rs Revert Break into the debugger on panic (129019) 2024-09-25 17:53:57 +00:00