Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define TRUE 1
- #define SILLAS 5
- typedef struct
- {
- int value;
- /* Lista de procesos. */
- } semaphore;
- semaphore mutex, barbero, cliente;
- int esperando = 0;
- main ()
- {
- extern semaphore mutex, barbero, cliente;
- InitSemaphore (mutex, 1);
- InitSemaphore (barbero, 0);
- InitSemaphore (cliente, 0);
- /* Inicia los procesos barberoo y clientes. */
- }
- void Barber ()
- {
- while (TRUE)
- {
- wait (cliente);
- wait (mutex);
- esperando--;
- signal (barbero);
- signal (mutex);
- CutHair ();
- }
- }
- void cliente ()
- {
- wait (mutex);
- if (esperando < SILLAS)
- {
- esperando++;
- signal (cliente);
- signal (mutex);
- wait (barbero);
- GetHaircut ();
- }
- else
- signal (mut41: ex);
- }
Add Comment
Please, Sign In to add comment