Skip to content

Commit

Permalink
Make Thread::new_inner a safe function
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisDenton committed Jul 18, 2024
1 parent a605e2f commit 939ee38
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions library/std/src/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1337,21 +1337,19 @@ pub struct Thread {
impl Thread {
/// Used only internally to construct a thread object without spawning.
pub(crate) fn new(name: ThreadNameString) -> Thread {
unsafe { Self::new_inner(ThreadName::Other(name)) }
Self::new_inner(ThreadName::Other(name))
}

pub(crate) fn new_unnamed() -> Thread {
unsafe { Self::new_inner(ThreadName::Unnamed) }
Self::new_inner(ThreadName::Unnamed)
}

// Used in runtime to construct main thread
pub(crate) fn new_main() -> Thread {
unsafe { Self::new_inner(ThreadName::Main) }
Self::new_inner(ThreadName::Main)
}

/// # Safety
/// If `name` is `ThreadName::Other(_)`, the contained string must be valid UTF-8.
unsafe fn new_inner(name: ThreadName) -> Thread {
fn new_inner(name: ThreadName) -> Thread {
// We have to use `unsafe` here to construct the `Parker` in-place,
// which is required for the UNIX implementation.
//
Expand Down

0 comments on commit 939ee38

Please sign in to comment.