martes, 4 de octubre de 2011

EXAMEN

#include "rshmem.h"
#include <stdlib.h>
#include <sys/sem.h>
#include <math.h>
#include <time.h>
#define N 5 
typedef int semaphore;                                                    
int state[N];                                                             
semaphore mutex=1;                                                        
semaphore s[N];                                                           
viod philosopher(int i)                                                   
{
 incrementa (int *mem, int k){
int i;
i=*mem;
TP ; TP ; TP TP ;
TP ; TP TP ; TP ;
TP TP ; TP ; TP
i=i+k;
TP ; TP ; TP TP ;
TP ; TP TP ; TP ;
TP TP ; TP ; TP
*mem=i;

 }

filosofo(FILE *pf, key_t *sclave, int *sfilo, int i, int *comer, int *fin, int *fc){
while (true){                                                             
think();                                                                  
take_forks(i);                                                            
eat();                                                                    
put_forks(i);                                                             
}
}
void take_forks(int i)                                                    
{
down(&mutex);                                                             
state[i] = HUNGRY;                                                        
test(i);                                                                  
up(&mutex);                                                               
down(&s[i]);                                                              
}                                                                                   
void put_forks(i)                                                         
{                               
down(&mutex);                                                             
state[i] = THINKING;                                                      
test(LEFT);                                                               
test(RIGHT);                                                              
up(&mutex);                                                               
}
void test(i)                                                              
{
if(state[i] == HUNGRY && state [LEFT]!= EATING && state [RIGHT]!=EATING){
state[i]=EATING;
up(&s[i]);
}
}

No hay comentarios:

Publicar un comentario