Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int parent(void){
- puts("This is the Parent Process");
- int philosopherState;
- char* philprint;
- int count=0;
- int c;
- while (1){
- sleep(1);
- for(int o = 0; o<N;o++ ){
- sem_wait(&shared->mutex);
- philosopherState = shared->state[o];
- if (philosopherState == 0) {
- philprint = "Thinking";
- }else if(philosopherState == 1){
- philprint = "Eating";
- }else if(philosopherState == 2){
- philprint = "Hungry";
- }else if(philosopherState == 3){
- philprint = "Gone";
- count++;
- }
- sem_getvalue(&shared->s[o], &c);
- printf("P%d %s \t",o, philprint);
- //printf("P%d %s\t",o, c == 0 ? "Eating" : "Hungry");
- if (count >4){
- break;
- }
- }
- sem_post(&shared->mutex);
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement