void rev_philosopher(void *arg) { int i; long p=(long) arg; while(1) { for (i=0;i<100000;i++); rev_getForks(p); for (i=0;i<100000;i++); putForks(p); } exit(); }
void* philosopher(void* i){ int p = *((int*)i); // Free memory area that was allocated for the params free(i); while(1){ think(p); takeForks(p); eat(p); putForks(p); } return 0; }
void exist(int philo) { while (1) { // Simulate the normal activities of a philosopher at dinner. //Think printf("%s is thinking...\n", philosophers[philo]); randomwait(PHILOSOPHER_AMOUNT); getForks(philo); pthread_mutex_lock(&mutex); //Eat printf("%s is eating...\n", philosophers[philo]); randomwait(PHILOSOPHER_AMOUNT); pthread_mutex_unlock(&mutex); putForks(philo); printf("%s is done.\n", philosophers[philo]); } }