I've been learning how to do multi-threading in C and wanted to use <threads.h>. But it (my compiler GCC 8.1) says that <threads.h> isn't a file or a directory when I wanted to compile this code :
#include <stdio.h>
#include <stdlib.h>
#include <threads.h>
int main(void) {
printf("Hello World\n");
return EXIT_SUCCESS;
}
So yeah... a hello world program but at the compile-time it doesn't work. Help me please. Also I am using Code::Blocks.
The threads.h
library doesn't have wide support among compilers, as most OSs have their own threading implementation.
Since you're using GCC, try using pthreads
instead. If you're using the MinGW variant on Windows, you'll need to use the Windows threading functions instead.
GNU Gnulib defines thread.h, which is documented to support MinGW (Minimalist GNU for Windows). MinGW includes a GCC distribution.
See the Gnulib thread.h documentation.
I have not tried this myself, but you may find it helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With