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=c99option. Using strict C mode disables a bunch of stuff, including something that stopspthread_barrier_tfrom getting defined. If you use-std=gnu99instead, it should compile. (Tested on Ubuntu 16.04 on WSL).Alternatively, add
or
before the first
#includein your source. Seeman 7 feature_test_macrosfor the acceptable values of these macros and more information.