I guess, that I am still not understanding the logic of working with threads. I have a program that has an amount of servers in different stations that are going to help with the thread requests.I am going to have an array of Threads. So every server should process the thread. In this case I just have to get the arriving time of every thread and the time when the thread exists . However, the Thread does not get to Critical Region
Here is the code:
void *Thread(void *parm)
{
int i;
int n
for(i=0; i< stations; i++)
{
tidp[n].Schedule[n]=time();
pthread_mutex_lock(&(mutex[i]));
if(StationArr[i] > 0)
StationArr[i]--;
pthread_cond_wait(&(cond[i]), &(mutex[i]) );
printf("Processing Thread request");
pthread_mutex_unlock(&(mutex[i]));
sleep(Exp(Exp[i]));
pthread_mutex_lock(&(mutex[i]));
StationArr[i]++;
tidp[n].Schedule[n]=time();
printf("Service is finished");
pthread_cond_signal(&(cond[i]));
pthread_mutex_unlock(&(mutex[i]));
}
}
How can I create a working thread?