Mach-O thread-local storage

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

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

See MWE - tls.c - attached here

Attachments: 

AttachmentSize
Downloadtext/x-csrc tls_1.c1.55 KB

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

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

Thanks,

Jennifer

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

Thanks.

Leave a Comment

Please sign in to add a comment. Not a member? Join today