Quantum Spoons - The NO Solution
pthread_mutex_t * block_monitor;
block_monitor = (pthread_mutex_t * ) malloc ( sizeof (pthread_mutex_t) );
t_philo * persons;
persons = (t_philo * ) malloc ( sizeof (t_philo) * 5 );
pthread_t * threads;
threads = (pthread_t * ) malloc ( sizeof (pthread_t) * 5 );
int * block_length;
block_length = (int * ) malloc ( sizeof (int) * 5 );
int * block_start;
block_start = (int * ) malloc ( sizeof (int) * 5 );
mutex setup (STL function)
pthread_mutex_t * block_monitor;
block_monitor = (pthread_mutex_t * ) malloc ( sizeof (pthread_mutex_t) );
pthread_mutex_init ( block_monitor, NULL );
int * block_length, * block_start;
block_length = (int * ) malloc ( sizeof (int) * 5 );
block_start = (int * ) malloc ( sizeof (int) * 5 );
i = - 1 ;
while (++ i < how_many_people)
{
block_length[i] = 0 ;
block_start[i] = - 1 ;
}
table (ie. philosophers setup ) . pthread_create
(STL)
t0 = time (0 );
i = - 1 ;
while (++ i < how_many_people)
{
persons[i].id = i;
persons[i].t0 = t0;
persons[i].v = initialize_v ( how_many_people );
persons[i].ms = atoi (argv[2 ]);
persons[i].block_length = block_length;
persons[i].block_start = block_start;
persons[i].block_monitor = block_monitor;
persons[i].how_many_people = how_many_people;
pthread_create ( & threads[i], NULL, philosopher, (void * ) (& persons[i]) );
}
int pthread_create
(
pthread_t * restrict thread, ~ & threads[i]
const pthread_attr_t * restrict attr, ~ NULL
void * (* start_routine)(void* ), ~ ` philosopher`
void * restrict arg ~ (void* ) (& persons[i])
);
* ` philosophers` is ` void * philosopher(void * v)`
/* both ways work the same * /
pthread_create( & threads[i], NULL, philosopher, (void * ) (& persons[i]) );
pthread_create( threads + i, NULL, philosopher, (void * ) (persons + i) );