Skip to content

Commit 69b9bae

Browse files
committed
Guarantee 8 bytes of alignment in Thread::into_raw
1 parent 175e043 commit 69b9bae

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

library/std/src/thread/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,11 @@ where
13801380
}
13811381

13821382
/// The internal representation of a `Thread` handle
1383+
///
1384+
/// We explicitly set the alignment for our guarantee in Thread::into_raw. This
1385+
/// allows applications to stuff extra metadata bits into the alignment, which
1386+
/// can be rather useful when working with atomics.
1387+
#[repr(align(8))]
13831388
struct Inner {
13841389
name: Option<ThreadNameString>,
13851390
id: ThreadId,
@@ -1563,7 +1568,8 @@ impl Thread {
15631568
/// Consumes the `Thread`, returning a raw pointer.
15641569
///
15651570
/// To avoid a memory leak the pointer must be converted
1566-
/// back into a `Thread` using [`Thread::from_raw`].
1571+
/// back into a `Thread` using [`Thread::from_raw`]. The pointer is
1572+
/// guaranteed to be aligned to at least 8 bytes.
15671573
///
15681574
/// # Examples
15691575
///

0 commit comments

Comments
 (0)