-
-
Notifications
You must be signed in to change notification settings - Fork 26
Description
Specifically, because ThreadExt::get_native_id
(and thus all of the other methods) doesn't get the native id, it gets the id of the current thread.
As an example:
let current_thread_id = std::thread::current().get_native_id();
let spawned_thread_id = std::thread::spawn(|| ()).thread().get_native_id();
assert_ne!(current_thread_id, spawned_thread_id); // panics
Or written another way:
let parent_thread = std::thread::current();
let parent_thread_id = parent_thread.get_native_id();
std::thread::spawn(|| {
assert_eq!(parent_thread_id, parent_thread.get_native_id()); // panics
}).join().unwrap();
Removing the extension trait or adding a check that self == thread::current()
is required to not be giving actively misleading results.
std::thread::JoinHandle
actually supports getting the raw OS handle on cfg(windows)
via AsRawHandle::as_raw_handle
and cfg(unix)
via JoinHandleExt::as_pthread_t
. Perhaps it's not completely unreasonable to suggest that we could get similar extension trait access to the OS handle for std::thread::Thread
. Until we do, though, ThreadExt
is impossible to implement in the implied way of actually getting the data for the represented thread.