Beispiel #1
0
void philosopher (void *data)
{
	int i;

	i = (int) data;
	for (;;) {
		think (i);
		get_forks (i, &fork [i], &fork [(i+1) % N]);
		eat (i);
		put_forks (&fork [i], &fork [(i+1) % N]);
	}
}
/* the philosopher thread function - create N threads, each of which calls 
 * this function with its philosopher number 0..N-1
 */
void *philosopher_thread(void *context) 
{
    int philosopher_num = (int)context; /* hack... */

    while (1) {
        sleep_exp(4.0);
        get_forks(philosopher_num);
        sleep_exp(2.5);
        release_forks(philosopher_num);
    }
    
    return 0;
}