I am trying to parallelize an algorithm in C. I want to use pthread_barrier_t
but my Ubuntu wsl can't find it for some reason. I have pthread.h
included and I can use the rest of the pthread functions. libthread.a
is installed.
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
/* Error occurs here */
pthread_barrier_t barrier;
Exact error is: "identifier pthread_barrier_t is undefined"
I saw elsewhere it could be the way I'm compiling.
Compiling as follows:
gcc -o test test.c -Wall -std=c99 -lpthread -lm
Also, VS Code can't identify the function.
The problem is your -std=c99
option. Using strict C mode disables a bunch of stuff, including something that stops pthread_barrier_t
from getting defined. If you use -std=gnu99
instead, it should compile. (Tested on Ubuntu 16.04 on WSL).
Alternatively, add
#define _XOPEN_SOURCE 600 /* Or higher */
or
#define _POSIX_C_SOURCE 200112L /* Or higher */
before the first #include
in your source. See man 7 feature_test_macros
for the acceptable values of these macros and more information.