Proposal for C2x
WG14 N2291

Title:

Removal of _Thread_local

Author:

Rajan Bhakta

Date:

2018/08/02

Abstract: The _Thread_local keyword and storage class specifier has little or no utility for programs that do not use threads. This proposal is to make _Thread_local be a valid keyword if (not if and only if) __STDC_NO_THREADS__ is not defined by the implementation.

Prior art: N/A.
Similar facilities: _Complex, _Atomic, Variable Length Arrays


 

Introduction and motivation:

 

I believe the __STDC_NO_THREADS__ macro was introduced to allow C implementations to not support C standard threads. In practice this means that having thread local storage makes no sense as there is only one thread of execution. As such, the _Thread_local keyword should be put into the list of things that need not be supported if the macro is defined. This would bring it in line with atomic types, complex types and VLAÕs, all of which have syntax that is not present if the corresponding macro is defined by the implementation.

 

Benefits of adopting this proposal:

-       Provides an easier way of conforming to the C standard for hosted implementations

-       Provides an easier way of conforming to the C standard for freestanding implementations (listed separately as I believe this more important for implementers in this space)

-       Keeps threading support in the standard grouped together

-       Existing implementations (if any) can continue working with _Thread_local as an extension

 

Drawbacks:

-       Any existing programs depending on having _Thread_local in their code as part of a portable program may now not be portable. I believe this to be a vanishingly small set as there is no need for this storage class specifier for non-threaded programs.

 


 

Proposed changes to the C18 standard (in the style of _Complex):

 

6.2.4#4:

Change:

An object whose identifier is declared with the storage-class specifier _Thread_local has thread storage duration.

To:

            An object whose identifier is declared with the storage-class specifier _Thread_local has thread storage duration (threading support is a conditional feature that implementations need not support; see 6.10.8.3).

 

6.7.1:

Append after paragraph 4:

The storage class specifier _Thread_local shall not be used if the implementation does not support threads (see 6.10.8.3).

 

6.8.3#1:

Change:

__STDC_NO_THREADS__ The integer constant 1, intended to indicate that the implementation does not support the <threads.h> header.

To:

__STDC_NO_THREADS__ The integer constant 1, intended to indicate that the implementation does not support the _Thread_local storage class specifier or the <threads.h> header.