void phi_put_forks_condvar(int i) { down(&(mtp->mutex)); //--------into routine in monitor-------------- // LAB7 EXERCISE1: YOUR CODE state_condvar[i]=THINKING; // I ate over phi_test_condvar(LEFT);// test left and right neighbors phi_test_condvar(RIGHT); //--------leave routine in monitor-------------- if(mtp->next_count>0) up(&(mtp->next)); else up(&(mtp->mutex)); }
void phi_take_forks_condvar(int i) { down(&(mtp->mutex)); //--------into routine in monitor-------------- // LAB7 EXERCISE1: YOUR CODE state_condvar[i]=HUNGRY; // I am hungry phi_test_condvar(i);// try to get fork //--------leave routine in monitor-------------- if(mtp->next_count>0) up(&(mtp->next)); else up(&(mtp->mutex)); }
void phi_put_forks_condvar(int i) { down(&(mtp->mutex)); //--------into routine in monitor-------------- // LAB7 EXERCISE1: 2013011377 // I ate over // test left and right neighbors //--------leave routine in monitor-------------- state_condvar[i] = THINKING; phi_test_condvar(LEFT); phi_test_condvar(RIGHT); #ifdef HANSEN up(&(mtp->mutex)); #else if(mtp->next_count>0) up(&(mtp->next)); else up(&(mtp->mutex)); #endif //HANSEN }
void phi_take_forks_condvar(int i) { down(&(mtp->mutex)); //--------into routine in monitor-------------- // LAB7 EXERCISE1: YOUR CODE // I am hungry // try to get fork // I am hungry state_condvar[i]=HUNGRY; // try to get fork phi_test_condvar(i); while (state_condvar[i] != EATING) { cond_wait(&mtp->cv[i]); } //--------leave routine in monitor-------------- up(&(mtp->mutex)); }
void phi_take_forks_condvar(int i) { down(&(mtp->mutex)); //--------into routine in monitor-------------- // LAB7 EXERCISE1: 2013011371 // I am hungry // try to get fork state_condvar[i] = HUNGRY; phi_test_condvar(i); while (state_condvar[i] != EATING){ cond_wait(&mtp->cv[i]); } //--------leave routine in monitor-------------- if(mtp->next_count>0) up(&(mtp->next)); else up(&(mtp->mutex)); }
void phi_take_forks_condvar(int i) { down(&(mtp->mutex)); //--------into routine in monitor-------------- // LAB7 EXERCISE1: 2012011384 // I am hungry state_condvar[i]=HUNGRY; // try to get fork phi_test_condvar(i); while (state_condvar[i] != EATING) { cprintf("phi_take_forks_condvar: %d didn't get fork and will wait\n",i); cond_wait(&mtp->cv[i]); } //--------leave routine in monitor-------------- if(mtp->next_count>0) up(&(mtp->next)); else up(&(mtp->mutex)); }
void phi_take_forks_condvar(int i) { down(&(mtp->mutex)); //--------into routine in monitor-------------- // LAB7 EXERCISE1: 2009011419 // I am hungry state_condvar[i] = HUNGRY; // try to get fork phi_test_condvar(i); if (state_condvar[i] != EATING) { cond_wait(&mtp->cv[i]); } //--------leave routine in monitor-------------- if (mtp->next_count > 0) { up(&(mtp->next)); } else { up(&(mtp->mutex)); } }
void phi_take_forks_condvar(int i) { down(&(mtp->mutex)); //--------into routine in monitor-------------- // LAB7 EXERCISE1: YOUR CODE // I am hungry state_condvar[i] = HUNGRY; // try to get fork phi_test_condvar(i); while(state_condvar[i] != EATING) { cprintf("philosopher %d fails to take fork and will wait. \n"); cond_wait(& (mtp -> cv[i])); } //--------leave routine in monitor-------------- if(mtp->next_count>0) up(&(mtp->next)); else up(&(mtp->mutex)); }
void phi_take_forks_condvar(int i) { down(&(mtp->mutex)); //进入管程 //--------into routine in monitor-------------- // LAB7 EXERCISE1: 2012011364 // I am hungry state_condvar[i] = HUNGRY; // try to get fork phi_test_condvar(i); //--------leave routine in monitor-------------- if ( state_condvar[i] != EATING) { //取刀叉失败时 cond_wait(&mtp->cv[i]); //等待条件变量 } if(mtp->next_count>0) up(&(mtp->next)); else up(&(mtp->mutex)); }