Open CAD97 opened 1 year ago
Hi @CAD97! Thank you for your report.
Let me answer.
Thread::id()
.JoinHandle
might not be the same as the get_native_id()
for the reasons I mentioned above. For now, I work with threads on UNIX via pthread and on windows via native windows threads, so it should work. But if someone expects to have a gettid()
returned on Linux, this wouldn't be the case. If we have a JoinHandleExt
which has JoinHandleExt::get_native_id()
, then we will become dependent on pthread implementation and native windows threads and on the JoinHandle::as_raw_handle()
and JoinHandle::as_pthread_t()
implementation (and existence) too.To sum up: I'll add a check and then think of how we can use (and whether or not it will be enough and good enough) the existing Rust methods.
I have an idea of creating a separate structure called ThreadExt
or PrioritisedThread
, which would encapsulate the std::thread::Thread
inside and a native thread id (as I call it). How does that sound to you?
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:
Or written another way:
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 oncfg(windows)
viaAsRawHandle::as_raw_handle
andcfg(unix)
viaJoinHandleExt::as_pthread_t
. Perhaps it's not completely unreasonable to suggest that we could get similar extension trait access to the OS handle forstd::thread::Thread
. Until we do, though,ThreadExt
is impossible to implement in the implied way of actually getting the data for the represented thread.