Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
37 Views

Mach-O thread-local storage

I'm trying to compile some C code which makes use of the __thread keyword, to indicate thread-local storage, but on OS X (Mavericks) I get the following error:

./tls.c(6): error #1781: thread-local storage is not supported in this environment
     static long __thread x[MAX_SLOTS];

Whilst investigating the error, I've found that although Mach-O object files don't provide a dedicated area for thread-local storage variables (like ELF object files apparently do) other OS X compilers (e.g. clang 5.0 and gcc-4.8) do recognise and compile files containing __thread.

I did find some Intel documentation regarding the __thread keyword, which suggests using the compile argument -gcc-version=XXX, but this just prints out a deprecation warning and still results in the above error. (I tried adding a hyperlink to the page I found, but this triggers the spam filter)

I attach a fairly simple MWE in C99, which creates some threads that access TLS. The pthreads workaround (using pthread_key_create, pthread_setspecific, pthread_getspecific and pthread_key_delete) adds a lot of code bloat that would be desirable to avoid.

Compile command used:-

   [compiler] ./tls.c -o tls -std=c99 -Wall

where compiler was one of gcc-4.8, clang or icc

0 Kudos
4 Replies
Highlighted
Beginner
37 Views

See MWE - tls.c - attached here

0 Kudos
Highlighted
37 Views

Hi albl500,

Unfortunately, Intel C++ compiler currently does not support TLS. Sorry about that -- we intend to introduce TLS support in 15.0, but please don't consider this to be an official "promise" (the only thing I can guarantee is that we are working on this).

Andrey

0 Kudos
Highlighted
Moderator
37 Views

I've added  your request to our database. when the feature is available, we will let you know.

Thanks,

Jennifer

0 Kudos
Highlighted
37 Views

The TLS support for Mac has been added into 15.0 compiler.  FYI.

Thanks.

0 Kudos