Untitled
By: a guest | Sep 2nd, 2010 | Syntax:
None | Size: 1.21 KB | Hits: 20 | Expires: Never
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace scratchpad
{
class Customer
{
static Semaphore chairs;
static Semaphore barber;
static Semaphore barberShop;
static void Main(string[] args)
{
string name = args[0];
int chairNum = int.Parse(args[1]);
int custNum = int.Parse(args[2]);
chairs = new Semaphore(chairNum, chairNum, "chairs");
barber = new Semaphore(1, 1, "barber");
customerStuff(name, chairNum, custNum);
}
static void customerStuff(string name, int chairsNum, int custNum)
{
Console.WriteLine("Customer "+name+" has arrived");
bool chairFree = chairs.WaitOne(1, false);
if (!chairFree)
Console.WriteLine("Customer " + name + " could not find a chair and is leaving");
else
Console.WriteLine("Customer " + name + " has arrived");
barber.WaitOne();
chairs.Release();
barberShop.Release();
barber.Release();
}
}
}