Mingw-w64 C11 threads.h not found?

Viewed 1589

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.

1 Answers

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.

Related