/*************************************************************************** * Le dinner des philosophes * * Two phase locking: * * - array de baguettes * * - manger(): tente l'acquisition des deux. attente passive si non dispo * ****************************************************************************/ #include #include #include #define TABLE_SIZE 5 #define RIGHT(x) ((x)) % TABLE_SIZE #define LEFT(x) ((x)+1) % TABLE_SIZE typedef unsigned int PHILOSOPHE; // philosophe's id in the table pthread_mutex_t baguettes[TABLE_SIZE], tableLock; int main(void) { } void penser(){ usleep(100 + rand() % 500); } void manger(){ usleep(100 + rand() % 500); } void prendre(){ } void deposer(){ } void* thread_philosophe(void* arg){ while(42){ penser(); prendre(); manger(); deposer(); } }