[PATCH v8 1/8] nptl: Add C11 threads thrd_* functions

Florian Weimer fweimer@redhat.com
Thu Jul 12 18:25:00 GMT 2018


On 07/12/2018 07:52 PM, Adhemerval Zanella wrote:
> 
> 
> On 12/07/2018 13:46, Florian Weimer wrote:
>> On 02/02/2018 06:04 PM, Adhemerval Zanella wrote:
>>
>>> diff --git a/include/stdc-predef.h b/include/stdc-predef.h
>>> index c569759..c2ab78a 100644
>>> --- a/include/stdc-predef.h
>>> +++ b/include/stdc-predef.h
>>> @@ -57,7 +57,4 @@
>>>       - 3 additional Zanabazar Square characters */
>>>    #define __STDC_ISO_10646__        201706L
>>>    -/* We do not support C11 <threads.h>.  */
>>> -#define __STDC_NO_THREADS__        1
>>
>> Should we do this only if we know that the compiler has _Thread_local support (based on a GCC and __cplusplus version check)?
> 
> It seems reasonable, since its a installed header.  Do we need to
> check for __cplusplus too? Shouldn't __GNUC_PREREQ (4.9) be suffice?

I think we can use __thread instead of _Thread_local with even older 
compilers, and also factor in __cplusplus if it is recent enough 
(essentially 2011 and later) for the !__GNUC__ case.

Maybe it's sufficient to say

#if !defined (__GNUC__) && !defined (__cpluscplus) \
   &&  __cplusplus < 201103L)
# define __STDC_NO_THREADS__        1
#endif

On the other hand, maybe your original change is right because in C11, 
_Thread_local support is not optional.  Implementations are required to 
recognize the keyword (and presumably ignore it) even if they define 
__STDC_NO_THREADS__.  And our <threads.h> will generally work fine even 
if the compiler does not actually support _Thread_local.  So I'd say go 
with your original change.

(But I do think you need to do something about thread_local in the C++ 
case, independently of this discussion.)

Thanks,
Florian



More information about the Libc-alpha mailing list