On Wednesday 07 October 2026 12:15:00 Kirill Makurin wrote:
> Pali Rohár <[email protected]> wrote:
> 
> > On Wednesday 07 October 2026 08:45:57 Kirill Makurin wrote:
> >> LIU Hao wrote:
> >> > The Microsoft `thrd_t` is a structure of two fields: the handle is for 
> >> > `thrd_join()`, and the numeric
> >> > identifier is for `thrd_equal()`. But there still be issue if 
> >> > `thrd_detach(thrd_current())` is called.
> >>
> >> Maybe following MSVC ABI is not the best idea after all...
> >
> > vcruntime140_threads.dll implementation does support 
> > thrd_detach(thrd_current()).
> >
> > thrd_current() returns NULL handle with the correct thread id.
> 
> The issue here that any existing instance of `thrd_t` for the thread will not 
> be updated, and will contain old handle value.

I think that this is not a problem because:
- every existing instance contains the required information about thread
  (which is thread id) and this is always correct
- for comparing two instances is needed to use thrd_equal() function
  which even in the vcruntime140_threads.dll is using the thread id (and
  not thread handle)
- if needed, thread id can be converted to handle by opening a thread by
  id (there is a winapi function for it)

Maybe it is not easy to use this structure, but it contains all data for
thread identification and usage.

> > But it does not mean that there cannot be other thrd_detach()
> > implementation which will use same above memory/struct ABI but will
> > implement thrd_detach() differently to support also thrd_current().
> 
> - Kirill Makurin


_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to