TrabalhosGratuitos.com - Trabalhos, Monografias, Artigos, Exames, Resumos de livros, Dissertações
Pesquisar

Barbeiro Dorminhoco

Artigos Científicos: Barbeiro Dorminhoco. Pesquise 860.000+ trabalhos acadêmicos

Por:   •  30/3/2014  •  1.099 Palavras (5 Páginas)  •  399 Visualizações

Página 1 de 5

Barbeiro Dorminhoco

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading;

namespace ConsoleApplication1

{

class Program

{

int i;

static Random Rand = new Random();

const int MaxCustomers = 25;

const int NumChairs = 5;

static Semaphore waitingRoom = new Semaphore(NumChairs, NumChairs);

static Semaphore barberChair = new Semaphore(1, 1);

static Semaphore barberPillow = new Semaphore(0, 1);

static Semaphore seatBelt = new Semaphore(0, 1);

static bool AllDone = false;

static void Barber()

{

while (!AllDone)

{

Console.WriteLine("Barbeiro Dormindo...zzzZZZZ");

barberPillow.WaitOne();

if (!AllDone)

{

Console.WriteLine("O Barbeiro está cortando o Cabelo...");

Thread.Sleep(Rand.Next(1, 3) * 1000);

Console.WriteLine("O Barbeiro terminou o corte de Cabelo!");

seatBelt.Release();

}

else

{

Console.WriteLine("Barbeiro vai");

}

}

return;

}

static void Customer(Object number)

{

int Number = (int)number;

Console.WriteLine("Cliente {0} Entrou na Barbearia! ", number);

Thread.Sleep(Rand.Next(1, 5) * 1000);

Console.WriteLine("Cliente {0} Sentou na sala de espera. ", number);

waitingRoom.WaitOne();

...

Baixar como (para membros premium)  txt (2.9 Kb)  
Continuar por mais 4 páginas »
Disponível apenas no TrabalhosGratuitos.com