void PhilThread(Philosopher &p)
{
	PAction na;
	size_t d;

	while (true)
	{
		std::tie(na,d) = p.task_queue.next();
		switch(na)
		{
			case PAction::Thinking:
				p.thinking(milliseconds{d*10});
				break;
			case PAction::Eating:
				p.eat(milliseconds{d*10});
				break;
			case PAction::Waiting:
				break;
			case PAction::Finished:
				return;
				break;

		}
	}

}
示例#2
0
// Each philosopher is thinking and eating
void* Philosopher::start(void* i){
  Philosopher* p = (Philosopher*)i;
  sem_post(&p->var_i);
  while(1){
    p->think();
    p->eat();
  }
}