Advertisement
Guest User

Untitled

a guest
Nov 11th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. int parent(void){
  2. puts("This is the Parent Process");
  3. int philosopherState;
  4. char* philprint;
  5. int count=0;
  6. int c;
  7.  
  8. while (1){
  9. sleep(1);
  10.  
  11. for(int o = 0; o<N;o++ ){
  12. sem_wait(&shared->mutex);
  13. philosopherState = shared->state[o];
  14.  
  15. if (philosopherState == 0) {
  16. philprint = "Thinking";
  17. }else if(philosopherState == 1){
  18. philprint = "Eating";
  19. }else if(philosopherState == 2){
  20. philprint = "Hungry";
  21. }else if(philosopherState == 3){
  22. philprint = "Gone";
  23. count++;
  24. }
  25. sem_getvalue(&shared->s[o], &c);
  26. printf("P%d %s \t",o, philprint);
  27. //printf("P%d %s\t",o, c == 0 ? "Eating" : "Hungry");
  28.  
  29. if (count >4){
  30. break;
  31. }
  32. }
  33. sem_post(&shared->mutex);
  34. printf("\n");
  35. }
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement