[Mesa-dev] [PATCH 1/2] c11/threads: implement thrd_current on Windows
Emil Velikov
emil.l.velikov at gmail.com
Mon Apr 24 11:26:13 UTC 2017
On 21 April 2017 at 16:45, Jose Fonseca <jfonseca at vmware.com> wrote:
> I reread http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf and is
> not explicit.
>
> But I checked C11 threads.h implementation and thrd_current also uses
> DuplicateHandle.
>
> So C11/threads_win32.h is correct. And ISO C11 standard commited screwed up
> here. Maybe they'll introduce thread ids at some point (MSVC's
> implementation has a non-standard _Thrd_id() function), and we can use it,
> but until then, it's better not pretend that thrd_current meets our needs
> because it doesn't.
>
Right, thanks for the clarification Jose!
Personally I won't go as far as "ISO C11 standard commited screwed up
here", since they are not the ones that wrote the threads
implementation in Windows.
Perhaps MS can address that if they see enough value in it, but even
then there's the older/released versions of Windows to think about.
That aside - can we reword the comment to something like the following:
/* GetCurrentThread() returns a pseudo-handle, which we need
* to pass to DuplicateHandle. Only the resulting handle can be used
* from other threads.
*
* Note that neither handle can be compared to the one by thread_create.
* Only the thread IDs - as returned by GetThreadId and GetCurrentThreadId
* can be compared directly.
*
* Other potential solutions would be:
* - define thrd_t as a thread Ids, but this would mean we'd need
to OpenThread for many operations
* - use malloc'ed memory for thrd_t. This would imply using TLS
for current thread.
*
* Neither is particularly nice.
*/
Thanks
Emil
More information about the mesa-dev
mailing list