chap4
This commit is contained in:
45
bac2/os/chap4/group.c
Normal file
45
bac2/os/chap4/group.c
Normal file
@ -0,0 +1,45 @@
|
||||
/***************************************************************************
|
||||
* 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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user