1

Switching my C program from pthreads, POSIX , <pthread.h> to the C11 standard <threads.h>.

Im on a MAC from 2019. Below is my error and my gcc -version output.

How do I upgrade to use <threads.h>?

Question's from 7 years ago say that it is not supported, is this still the case and why not support a 'standard'?

Error message:

ruby.c:5:10: fatal error: 'threads.h' file not found #include <threads.h>

gcc --version

Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1 Apple clang version 11.0.0 (clang-1100.0.33.17) Target: x86_64-apple-darwin19.6.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin

seamus
  • 2,681
  • 7
  • 26
  • 49
  • 1
    the newer the standards, especially in old, establish languages , the less 'standard' they are, and the less support they receive. – A P Jo Sep 08 '20 at 05:44
  • 2
    In many cases this transition would be considered a downgrade... for example, `pthreads` have better support across more compilers and devices (and some would argue, a better API as well). – Myst Sep 08 '20 at 06:52
  • 1
    Just so we're clear `pthread.h` **is** a standard ([it's in the POSIX standard](https://pubs.opengroup.org/onlinepubs/9699919799/)) – Myst Sep 08 '20 at 06:55
  • 1
    When a new standard or a new version of one is published, it takes some time for implemenations to be created, tested, and distributed. The age of the Mac is not directly relevant, but you do appear to have a pretty old version of the XCode command-line tools installed, and that matters. I am uncertain whether there is a version available that supports the *optional* threads feature, but I do hope that the latest versions conform either by providing it or by defining the feature test macro indicating that they do not provide it. – John Bollinger Sep 08 '20 at 13:39

1 Answers1

1

You don't, Posix is the standard. Thanks friends.

seamus
  • 2,681
  • 7
  • 26
  • 49
  • 3
    POSIX is *a* standard. C threads is also [part of] a standard. The only compelling reason I see for changing -- which would be non-trivial even with a C implementation that supports the threads option -- would be for portability to non-POSIX platforms, but in practice, the conversion does not necessarily yield the compatibility win one hopes for. – John Bollinger Sep 08 '20 at 17:06