mutex
is declared as part of your
main
function:
int main(int argc, char *argv[]) {
N = atoi(argv[1]);
sem_t mutex[N];
which makes it a local variable - its scope is limited to the set of curly brackets which most recently enclose it - the
main
function itself.
And then you try to use it within the
f0
function:
void* f0(int j) {
for(int i = 0; i < 100; i++) {
if(j < N-1){
sem_wait(&mutex[j]);
Because no global or local variable exists in the
f0
function, the system rightly complains.
Possibly, you want to make
mutex
either global (by declaring it outside the body of any function), or pass it as a parameter to the
f0
function along with
j