about summary refs log tree commit diff
path: root/library/std/src/thread/mod.rs
diff options
context:
space:
mode:
authorOrson Peters <orsonpeters@gmail.com>2025-07-13 00:58:12 +0200
committerOrson Peters <orsonpeters@gmail.com>2025-07-13 00:58:46 +0200
commit69b9bae57ded527f5fd7f036b6cc1cca0b462ac4 (patch)
tree96595b5df62e08fa9c851128b4495c2de15ce9d1 /library/std/src/thread/mod.rs
parent175e04331be56c5b4bdf77478434b1a5e0556770 (diff)
downloadrust-69b9bae57ded527f5fd7f036b6cc1cca0b462ac4.tar.gz
rust-69b9bae57ded527f5fd7f036b6cc1cca0b462ac4.zip
Guarantee 8 bytes of alignment in Thread::into_raw
Diffstat (limited to 'library/std/src/thread/mod.rs')
-rw-r--r--library/std/src/thread/mod.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs
index 26b2fb44724..2552d6316fa 100644
--- a/library/std/src/thread/mod.rs
+++ b/library/std/src/thread/mod.rs
@@ -1380,6 +1380,11 @@ where
 }
 
 /// The internal representation of a `Thread` handle
+/// 
+/// We explicitly set the alignment for our guarantee in Thread::into_raw. This
+/// allows applications to stuff extra metadata bits into the alignment, which
+/// can be rather useful when working with atomics.
+#[repr(align(8))]
 struct Inner {
     name: Option<ThreadNameString>,
     id: ThreadId,
@@ -1563,7 +1568,8 @@ impl Thread {
     /// Consumes the `Thread`, returning a raw pointer.
     ///
     /// To avoid a memory leak the pointer must be converted
-    /// back into a `Thread` using [`Thread::from_raw`].
+    /// back into a `Thread` using [`Thread::from_raw`]. The pointer is
+    /// guaranteed to be aligned to at least 8 bytes.
     ///
     /// # Examples
     ///