64

There have been a lot of questions about C11 and C11 threading, but I don't see a definitive answer anywhere:

Does any C library implement the C11 threading interface usable on GNU/Linux-like? e.g., provide the "optional" <threads.h> and the thread support library like thrd_create(), from the C11 standard near p. 376.

Ideally, I'd like to find a library that is common-ish, open-source or free, for common/generic/multi architecture (e.g., GNU/Linux, x86_64, or portable-ish).

A few of the more helpful and relevant SO links:

  • this one and this one on glibc;
  • this one that's talking about the standard;
  • this one about clang;
  • this one about C11 in general and this one about Windows and other platforms;
  • a lot more about C++11 threading, but I am only interested in C11.

Some non-starter options for libraries:

I am not interested in POSIX threads (many fine options), Windows, an IDE, nor C++11 (I know that GNU libstdc++ and LLVM/Clang libc++ provide C++11's std::thread, which uses -pthread)

Thanks!


(re-)Edit: question re-opened, so migrated content to answer to clean up.

Community
  • 1
  • 1
hoc_age
  • 1,945
  • 2
  • 18
  • 28
  • not that I have found: http://stackoverflow.com/questions/16244153/clang-c11-threads-h-not-found – Grady Player Jul 03 '14 at 15:28
  • @Grady - Thanks; your question was already link #4 above. :) Empirically, for example, `glibc` sets `__STDC_NO_THREADS__` to `1` as you note in your question. – hoc_age Jul 03 '14 at 15:47
  • oh sorry, I didn't click through enough. – Grady Player Jul 03 '14 at 16:11
  • @Grady - No worries; your question (from 1+ year ago!) illustrated part of the issue. My question became a bit more of a "survey paper" than I had intended, but if that is its only value, so be it. – hoc_age Jul 03 '14 at 16:19
  • Downvote/close care to comment? I tried to add value and summarize all current knowledge and options, to obviate digging through the 5+ other questions and sources/docs from 5+ libraries. I'd like to do better (or save my breath!) next time; please advise. – hoc_age Jul 03 '14 at 16:39
  • 1
    I wouldn't worry too much about a 6:1 ratio on what is tantamount to a tool shopping question (a well researched tool shopping question). – Grady Player Jul 03 '14 at 18:56
  • Just for future reference, the discussions on the musl mailing list about C11 thread support appear to be in the July, August, and September 2014 timeframes. – Michael Burr Nov 22 '14 at 17:52
  • @hoc_age I imagine the CV is because requests to find a software library are considered off-topic. – OJFord Feb 09 '15 at 14:49
  • 1
    glibc now has support, included in 2.28 – WorldSEnder Aug 02 '18 at 21:37

8 Answers8

22

musl now (as of Sep 2014-ish) implements C11 threads!

According to this recent musl mailing list post and other conversation on that list in Jul-Sep 2014, it appears that the musl library now (as of 2014-09-07) implements the C11 threads interface, though the comparison chart; does not as of this writing reflect this.

Since this question is re-opened, I moved this content to a proper answer.

hoc_age
  • 1,945
  • 2
  • 18
  • 28
  • Thanks, I just tried `musl-gcc figE_12.c` and was able to compile something with `` . I tried to on gcc, and could not. I'm using Debian stretch. `gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516` it gave me `fatal error: threads.h: No such file or directory` I tried linking with `-threads` but just got `error: unrecognized command line option ‘-threads’; did you mean ‘-pthread’?` Anyway musi worked. Thanks i'm up voting you. – Manny_Mar Jan 31 '19 at 05:32
18

Finally GNU LIBC 2.28 supports C11 ISO Threads.

I assume Archlinux, Gentoo and Suse Tumbleweed will support it quickly. Later in this year Fedora and Ubuntu and the others in 2019 or later.

Peter
  • 2,240
  • 3
  • 23
  • 37
12

https://github.com/jtsiomb/c11threads is a "Trivial C11 threads.h implementation over POSIX threads." contained in a single header.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
4

Hmmm, it looks like GCC 4.9.0 actually provides substantial support for C11 standards (at least since the web docs were modified on around the end of June, 2014.

From https://gcc.gnu.org/onlinedocs/gcc-4.9.0/gcc/Standards.html

A fourth version of the C standard, known as C11, was published in 2011 as ISO/IEC 9899:2011. GCC has substantially complete support for this standard, enabled with -std=c11 or -std=iso9899:2011. (While in development, drafts of this standard version were referred to as C1X.)

And from https://gcc.gnu.org/gcc-4.9/changes.html

ISO C11 atomics (the _Atomic type specifier and qualifier and the header) are now supported. ISO C11 generic selections (_Generic keyword) are now supported. ISO C11 thread-local storage (_Thread_local, similar to GNU C __thread) is now supported. ISO C11 support is now at a similar level of completeness to ISO C99 support: substantially complete modulo bugs, extended identifiers (supported except for corner cases when -fextended-identifiers is used), floating-point issues (mainly but not entirely relating to optional C99 features from Annexes F and G) and the optional Annexes K (Bounds-checking interfaces) and L (Analyzability). A new C extension __auto_type provides a subset of the functionality of C++11 auto in GNU C.

From that, it is hard to tell what all of that will really mean when the pedal hits the metal. An upgrade on an environment to the latest GCC 4.9.0 release and a few simple driver programs would confirm how much or how little it is being implemented.

Hope it helps.

luis.espinal
  • 10,331
  • 6
  • 39
  • 55
  • 6
    gcc support is a whole different kettle of fish to glibc support, though. – Crowman Jul 03 '14 at 15:45
  • 4
    Right; I am using `gcc-4.9.0` and `glibc-2.19` (believe current stable). The combination reports `__STDC_NO_THREADS__` as `1`, declaring [lack of support](http://gcc.gnu.org/wiki/C11Status) for the "optional" threads "feature," hence I'm looking elsewhere. :) For C *language* features and compiler-specific stuff, `gcc` supports (most of) C11 (e.g., syntax, semantics, compiler-specific headers, `libgcc` stuff). For different reasons, the `gcc` codebase bundles `libstdc++`, but `glibc` is *not* bundled in `gcc`, so C *library* stuff like `` and ilk are rather separate. – hoc_age Jul 03 '14 at 16:24
4

FreeBSD provides threads.h since FreeBSD 10.0 The program needs to be linked against libstdsthreads.

M.K. aka Grisu
  • 2,338
  • 5
  • 17
  • 32
2

PDCLib (the Public Domain C standard library) includes AFAICT full support for threads.h, and it's not a wrapper around pthreads.

MarcusJ
  • 149
  • 4
  • 12
0

FreeBSD seems to wrap around the posix threads. You can find it here: FreeBSD c11 threads. I was able to use this in Cygwin. So far no problems but I haven't used it that much yet.

annoying_squid
  • 513
  • 5
  • 10
0

There is TinyCThread which implements the threads.h API of standard C11. It wraps POSIX and Windows threads. It's quite easy to integrate in your project: it consists of one .h and one .c file.

tuket
  • 3,232
  • 1
  • 26
  • 41