Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clang c11 threads.h not found

I am trying to setup a c11 thread example in xcode... but it doesn't seem to have the threads.h header, though it isn't complaning about the macro described here:
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf

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

showing dialectshowing error

like image 857
Grady Player Avatar asked Apr 26 '13 19:04

Grady Player


3 Answers

Looks like almost nothing supports the threads feature in C11... maybe I will try to get it into clang...

like image 188
Grady Player Avatar answered Nov 12 '22 06:11

Grady Player


With the clang on my machine (v. 3.2 on ubuntu/linux) that feature test macro isn't defined. Support for that feature will need support in the C library, that usually doesn't come with the compiler. So basically the answer for clang will not be much different than for gcc, they usually build upon the same C library, namely glibc, see here for answer for gcc.

like image 41
Jens Gustedt Avatar answered Nov 12 '22 05:11

Jens Gustedt


Just in case anyone is looking this up in 2021+, Apple still doesn't support this, and likely never will. As others have stated, pthreads is by far the best bet. Note that widely, C11 threads are not supported. I would go as far as to say pthreads is more portable in most circumstances.

From a development perspective, C11 threads are much too limited, and obfuscate user space vs. kernel space implementation features, along with implementation attributes.

If you really need C11 threads I would recommend doing one of three things.

  1. Don't.
  2. Use a cross-platform library: https://github.com/tinycthread/tinycthread seems to do a good job.
  3. Write your own polyfill. The library I just mentioned tries to support a bunch of platforms (though it's inactive now), but anyone with a little bit of experience with pthreads and win32 threads will have no trouble (but, maybe a headache) writing a polyfill. I actually did this the other day out of interest, and it took just a few hundred lines, not too bad. For any project that will use it alot, this will give more control over usage.

The good thing to note is some other C11 features are supported on OSX, like C11 Atomics, which complementing would be impossible without a lot of ASM knowledge.

like image 1
Hunter Kohler Avatar answered Nov 12 '22 04:11

Hunter Kohler