cours_progra/bac2/os/chap4/group.c

46 lines
890 B
C
Raw Normal View History

2023-12-21 23:39:12 +01:00
/***************************************************************************
* Le dinner des philosophes *
* Two phase locking: *
* - array de baguettes *
* - manger(): tente l'acquisition des deux. attente passive si non dispo *
****************************************************************************/
#include <pthread.h>
#include <unistd.h>
#include <stdlib.h>
#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();
}
}