X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/dff9e15c44ab6340d27215957c56fa72fad246a2..cc01c6a871dbbfd0cc84e26eb9f94aeb539e613e:/examples/gras/synchro/philosopher.c diff --git a/examples/gras/synchro/philosopher.c b/examples/gras/synchro/philosopher.c index 528989242f..d4debb26d1 100644 --- a/examples/gras/synchro/philosopher.c +++ b/examples/gras/synchro/philosopher.c @@ -1,8 +1,7 @@ -/* $Id$ */ - /* philosopher - classical dinning philosopher as a demo xbt syncro stuff */ -/* Copyright (c) 2007 Martin Quinson. All rights reserved. */ +/* Copyright (c) 2007, 2009, 2010. The SimGrid Team. + * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -30,14 +29,14 @@ static void pickup(int id, int lunch) { INFO2("Thread %d gets hungry (lunch #%d)", id, lunch); xbt_mutex_acquire(mutex); - while (state[(id + (philosopher_amount - 1)) % philosopher_amount] == EATING - || state[(id + 1) % philosopher_amount] == EATING) { + while (state[(id + (philosopher_amount - 1)) % philosopher_amount] == + EATING || state[(id + 1) % philosopher_amount] == EATING) { xbt_cond_wait(forks[id], mutex); } state[id] = EATING; - xbt_assert1(state[(id + (philosopher_amount - 1)) % philosopher_amount] == - THINKING + xbt_assert1(state[(id + (philosopher_amount - 1)) % philosopher_amount] + == THINKING && state[(id + 1) % philosopher_amount] == THINKING, "Philosopher %d eats at the same time that one of its neighbors!!!", id); @@ -88,8 +87,8 @@ static void philo_thread(void *arg) /* Enter an endless loop to test the killing facilities */ INFO1 - ("Thread %d tries to enter the dead-end; hopefully, the master will cancel it", - id); + ("Thread %d tries to enter the dead-end; hopefully, the master will cancel it", + id); xbt_mutex_acquire(dead_end); INFO1("Oops, thread %d reached the dead-end. Cancelation failed", id); } @@ -130,7 +129,9 @@ int philosopher(int argc, char *argv[]) /* spawn threads */ for (i = 0; i < philosopher_amount; i++) { char *name = bprintf("thread %d", i); - philosophers[i] = xbt_thread_create(name, philo_thread, &id[i]); + philosophers[i] = + xbt_thread_create(name, philo_thread, &id[i], + 0 /*not joinable */ ); free(name); }