List * create_node(int priority, int previous_at, float u, float lamda){ List * node = malloc(sizeof(List)); node -> priority = priority; node -> arrTime = previous_at + random_time(u, lamda); node -> next = NULL; return node; }
void Think(int phil) { _T(pthread_mutex_lock(&aux_mutex)); int think_len = random_time(); think_time[phil] += think_len; printf("Philosopher %d is thinking for %d s\n", phil, think_len); _T(pthread_mutex_unlock(&aux_mutex)); sleep(think_len); _T(pthread_mutex_lock(&aux_mutex)); printf("Philosopher %d stopped thinking\n", phil); block_start[phil] = time(0); _T(pthread_mutex_unlock(&aux_mutex)); }
void Eat(int phil) { _T(pthread_mutex_lock(&aux_mutex)); block_time[phil] += time(0) - block_start[phil]; int eat_len = random_time(); eat_time[phil] += eat_len; Pickup(phil); printf("Philosopher %d is eating for %d s\n", phil, eat_len); _T(pthread_mutex_unlock(&aux_mutex)); sleep(eat_len); _T(pthread_mutex_lock(&aux_mutex)); printf("Philosopher %d stopped eating\n", phil); Pickdown(phil); _T(pthread_mutex_unlock(&aux_mutex)); }
struct tm *random_tm(void) { time_t t = random_time(); return localtime(&t); }