I'm trying to initialize arrays of mutexes and condition variables inside a function. The array is of type Cell which i deifined and each Cell contain mutex, condition variable and char. I'm getting the error on the 3 lines inside the for loop in intiail_circle:
expected expression before ‘{’ token.
I tried to initial the array also outside the function but it didn't help. any ideas what cause it?
the code:
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 5
#define num_of_cells (2*(2*N - 2))
typedef struct Generator{
pthread_t tid;
int id;
}Genarator;
typedef struct Car{
pthread_t carId;
int location ,GenID,num_of_steps;
}Car;
typedef struct Cell{
char val;
pthread_mutex_t mutex;
pthread_cond_t cond;
}Cell;
Cell circle[num_of_cells];
Cell generators_location[4];
struct Generator *generators[4];
int main(){
initial_circle();
}
void initial_circle(){
int i;
for(i = 0; i < num_of_cells; i++){
circle[i].mutex = PTHREAD_MUTEX_INITIALIZER;
circle[i].cond = PTHREAD_COND_INITIALIZER;
circle[i].val = ' ';
}
}