Skip to content

Commit

Permalink
Fix a pthread_t handle leak rust-lang#114610
Browse files Browse the repository at this point in the history
  • Loading branch information
g0djan committed Aug 16, 2023
1 parent 60713f4 commit 42a7080
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions library/std/src/sys/wasi/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ cfg_if::cfg_if! {
stack_size: libc::size_t,
) -> ffi::c_int;
pub fn pthread_attr_destroy(attr: *mut pthread_attr_t) -> ffi::c_int;
pub fn pthread_detach(thread: pthread_t) -> ffi::c_int;
}
}

Expand Down Expand Up @@ -178,6 +179,17 @@ impl Thread {
}
}

cfg_if::cfg_if! {
if #[cfg(target_feature = "atomics")] {
impl Drop for Thread {
fn drop(&mut self) {
let ret = unsafe { libc::pthread_detach(self.id) };
debug_assert_eq!(ret, 0);
}
}
}
}

pub fn available_parallelism() -> io::Result<NonZeroUsize> {
unsupported()
}
Expand Down

0 comments on commit 42a7080

Please sign in to comment.