Sem Exer
Sem Exer
D. Gachet
The Sleeping Barber
Semaphore mutex=1;
semáforo para exclusion mutua
Semaphore customers=0, cutting=0, barber=0;
clientes, si se esta cortando el pelo o no, si está dormido o no
int waiting=0, numChairs= ..;
process Customer[i=1..M]
process SleepingBarber
while (true) {
while (true) {
wait(mutex);
ver si hay sitio wait(customers);no hay clientes, me duermo
if (waiting<numChairs){
wait(mutex);
waiting++; al haber un customer más, wait aumenta quito la ocupacion de una silla porque voy a
waiting--;atender a un cliente
signal(customers);hay un customer más
signal(barber);
signal(mutex);
signal(mutex);
wait(barber); ahora me toca que me llegue la vez
wait(cutting);
signal(cutting);
cuando sea mi turno, ya me podrá cortar el pelo }
}
end SleepingBarber;
else up(mutex);
} si todas las sillas estaban ocupadas, no puedo entrar
end Customer;
D. Gachet
The Sleeping Barber
D. Gachet
Preguntas del tema 2 del examen
El semaforo se inicializa a 0.
B se bloquea, hace el wait, si B hace el signal dsps de opA()
D. Gache0
Exercises with semaphores
D. Gachet
Exercises with semaphores
D. Gachet
Exercises with semaphores
D. Gachet
Exercises with semaphores
Exercises with semaphores
D. Gachet
Exercises with semaphores
D. Gachet
Exercises with semaphores
D. Gachet
Exercises with semaphores
D. Gachet
Exercises with semaphores
D. Gache0
Exercises with semaphores
D. Gachet