about summary refs log tree commit diff
path: root/library/std/src/rt.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-10-24 13:35:50 +0000
committerbors <bors@rust-lang.org>2024-10-24 13:35:50 +0000
commitf61306d47bc98af8bb9d15f1adf6086785590a8c (patch)
tree0500da4d67b3ec4f77a8cb011074779c5c0315fb /library/std/src/rt.rs
parent5ae4d75effa366176dd75cd0d5662da26385cfc5 (diff)
parent0747f2898e83df7e601189c0f31762e84328becb (diff)
downloadrust-f61306d47bc98af8bb9d15f1adf6086785590a8c.tar.gz
rust-f61306d47bc98af8bb9d15f1adf6086785590a8c.zip
Auto merge of #123550 - GnomedDev:remove-initial-arc, r=Noratrieb
Remove the `Arc` rt::init allocation for thread info

Removes an allocation pre-main by just not storing anything in std::thread::Thread for the main thread.
- The thread name can just be a hard coded literal, as was done in #123433.
- Storing ThreadId and Parker in a static that is initialized once at startup. This uses SyncUnsafeCell and MaybeUninit as this is quite performance critical and we don't need synchronization or to store a tag value and possibly leave in a panic.
Diffstat (limited to 'library/std/src/rt.rs')
-rw-r--r--library/std/src/rt.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/library/std/src/rt.rs b/library/std/src/rt.rs
index 80e7c3c026b..b2492238bd3 100644
--- a/library/std/src/rt.rs
+++ b/library/std/src/rt.rs
@@ -110,7 +110,7 @@ unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
     // handle does not match the current ID, we should attempt to use the
     // current thread ID here instead of unconditionally creating a new
     // one. Also see #130210.
-    let thread = Thread::new_main(thread::current_id());
+    let thread = unsafe { Thread::new_main(thread::current_id()) };
     if let Err(_thread) = thread::set_current(thread) {
         // `thread::current` will create a new handle if none has been set yet.
         // Thus, if someone uses it before main, this call will fail. That's a