日期:2014-05-18 浏览次数:20916 次
public class Test
{
static SalesLady saleslady = new SalesLady(14, 0, 0);
static EventWaitHandle wh = new AutoResetEvent(false);
static void Main()
{
int[] moneies = { 10, 10, 5, 10, 5, 10, 5, 5, 10, 5, 10, 5, 5, 10, 5 };
Thread[] aThreadArray = new Thread[20];
Console.WriteLine("现在开始售票:");
for (int i = 0; i < moneies.Length; i++)
{
CustomerClass cc = new CustomerClass(i + 1, moneies[i]);
aThreadArray[i] = new Thread(cc.run);
aThreadArray[i].Start();
Thread.Sleep(0);
}
for (int i = 0; i < moneies.Length; i++)
{
try
{
aThreadArray[i].Join();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
Console.WriteLine("票已售完" + saleslady.memontoes);
Console.Read();
}
class SalesLady
{
public int memontoes, five, ten;
public SalesLady(int m, int f, int t)
{
memontoes = m;
five = f;
ten = t;
}
public String ruleForSale(int num, int money)
{
String s = null;
if (memontoes <= 0)
return "对不起,已经售完";
if (money == 5)
{
memontoes--;
five++