10
votes

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

4
Looks like it didn't find the threads.h file.Robert Harvey
that is what it looked like to me too :) that is supposed to be part of the startdard library in c11 if the STDC_NO_THREADS macro isn't 1Grady Player
I guess you ought to check that folder and see if threads.h is actually in there, and if it is, see if the compiler has access to it.Robert Harvey
doesn't seem to be in the xcode bundle... according to find /Applications/Xcode.app/Contents -name threads.hGrady Player
try #if !defined(__STDC_NO_THREADS) || __STDC_NO_THREADS__Kevin

4 Answers

3
votes

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

1
votes

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.

0
votes

it doesn't seem to have the threads.h header, though it isn't complaining

C11 has 2 specs about __STDC_NO_THREADS__

7.26 Threads
Implementations that define the macro __STDC_NO_THREADS__ need not provide this header nor support any of its facilities. C11 N1570 §7.26.1 2

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

Per §7.26.1 2:

#ifdef __STDC_NO_THREADS__
#error "No threading support"
#else
#include <threads.h>
#endif

Per §6.10.8.3:

#if defined(__STDC_NO_THREADS) && __STDC_NO_THREADS__ == 1
#error "No threading support"
#else
#include <threads.h>
#endif

// Certainly this can be simplified to
#if defined(__STDC_NO_THREADS) && __STDC_NO_THREADS__

or per What is the value of an undefined constant used in #if? to

#if __STDC_NO_THREADS__

This matches OP's code, so I would have expected that to work with a compliant C11 compiler.


Yet it looks like OP has a solution per @Kevin. That may be a false solution as __STDC_NO_THREADS looks like a typo (missing trailing __).

#if !defined(__STDC_NO_THREADS) || __STDC_NO_THREADS__
-16
votes

In C++11, you want to #include <thread>, not threads.h

#include <iostream>
#include <thread>

void fun() { std::cout << "fun!" << std::endl; }

int main() {
    std::thread t ( fun );
    t.join ();
    return 0;
}