Mingw-w64 C11 threads.h not found?
Asked Answered
M

1

6

I'm trying to use the C11 standard threading in my program, and I'm using the Mingw-w64 toolchain x86_64-8.1.0-posix-seh-rt_v6-rev0 specifically.

When I #include <threads.h> as the C11 standard defines, I get the No such file or directory error from gcc. I have found that I can #include <pthread.h> without error. I am passing the -std=c11 argument to gcc, btw.

I've searched high and low on the internet for any information about the standard C threading support. All I can find information on is for C++. Can somebody please explain to me why I can't use the C11 standard threads.h library?

EDIT: I've also checked if the STDC_NO_THREADS macro is defined. It seems to be undefined.

#ifdef __STDC_NO_THREADS__
printf("We got no threads capp'n!\n");
#endif

I get no message about not having threads.

Maremma answered 8/9, 2018 at 21:45 Comment(5)
mingw64 builds against msvcrt and not glibc. Check for the __STDC_NO_THREADS__ macro and if it's defined.Anticoagulant
It would seem to be UNDEFINED.Maremma
Also, I don't see what msvcrt and glibc have to do with this?Maremma
C11 threads are not very well supported by C compilers or standard libraries. If you want to use them on Windows, look into Pelles C.Opulent
Well that sucks. I wonder why not? Especially since C++ seems to get support without a problem? I guess I have nothing left to do but to go complain or to fix it myself then...Maremma
K
0

I also meet this problem on Windows 11. There is no threads.h under Mingw-w64 and vs 2022. But if you want to use it you can install Msys2 and gcc on it. After installation you find the head file there! I add thread.h into the source file and test it. Of course gcc in Msys2 compiles it with no error and warning. And I finally add __STDC_NO_THREADS__ and __STDC_NO_ATOMICS__ into the source and the compiler passes the error that the macros are undeclared. So the compiler support the C11 standard Concurrency support library.

Kate answered 22/3, 2022 at 14:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.