barbero

Páginas: 2 (330 palabras) Publicado: 11 de mayo de 2015
//Autores Daniel Romero Calero y Diego Rodriguez Garcia
#include "recurso.h"
#include
#include
#include
#include "semaforo.h"

#define INFINITO 1
#define SILLAS 3#define CANTIDAD_CLIENTES 5
#define TIEMPO_LLEGADA_CLIENTES 1
#define TIEMPO_CORTE 3

Semaforo clientes;
Semaforo barberoListo;
Semaforo mutex;
int sillaLibre = 0;

void termina_cortar (char* from) {printf("%s corta el pelo al cliente\n",from);

}

void cortar_cliente (char* from) {

printf("%s se esta cortando el pelo\n",from);
}

void cliente_irse (char* from){

printf("%s se vade la barberia\n",from);

}

void* barbero (void* no_usa) {

printf("El barbero se pone a trabajar\n");

while (INFINITO) {

WAIT(&clientes);// Tratar de atender a un cliente. Sino hay, ir a dormir.
WAIT(&mutex); // (Ya está despierto) Tratar de modificar el numero. de sillas disponibles.
sillaLibre--; //Queda una silla en la sala
SIGNAL(&barberoListo); //Elbarbero esta listo para cortar
SIGNAL(&mutex); //Ya no se modificara el numero de silla libres.Desbloquear
printf ("El barbero empieza el corte de pelo de un cliente quedan %desperando.\n",sillaLibre);
// Aquí el barbero corta el pelo de un cliente
sleep(TIEMPO_CORTE);
termina_cortar("El barbero");
}
}

void* cliente (void* no_usa) {


printf ("Ciente entrando hay%d esperando\n",sillaLibre);
WAIT(&mutex); // Trata de acceder a una silla.
if (sillaLibre < SILLAS) {

sillaLibre++; // Se sienta en una silla.
SIGNAL(&clientes);// Avisaral barbero (el cual está esperando) que hay un cliente.
SIGNAL(&mutex); // Ya no se necesita bloquear el numero de sillas libres.
WAIT(&barberoListo);// El cliente espera a que el barberoesté listo para atenderlo.
// Se le corta el pelo al cliente.
cortar_cliente("El cliente");
} else { // Si no hay sillas libres.

SIGNAL(&mutex); // Desbloquear la...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Barbero
  • Barbero
  • Barbero
  • barbera
  • Barbero
  • El barbero de sevilla
  • Barbero Durmiente
  • Resumen barbero

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS