예제 #1
0
파일: Bakery.cs 프로젝트: Keruto/INNLV
        public void SellCookieTo(RegularCustomer customer)
        {
            if (_cookies.Count <= _cookiesSold) return;

            lock (_cookies[_cookiesSold++])
            {
                Console.WriteLine("\t\t\t\t\t" + customer.Name + " received cookie #" + _cookiesSold + " with " + _cookies[(_cookiesSold-1)].Type);
            }
        }
예제 #2
0
파일: Program.cs 프로젝트: Keruto/INNLV
        static void Main(string[] args)
        {
            var bakery = new Bakery();
            var bakeryT = new Thread(bakery.Work);
            bakeryT.Start();

            var fred = new RegularCustomer("Fred");
            var ted = new RegularCustomer("Ted");
            var greg = new RegularCustomer("Greg");
            var fredT = new Thread(() => fred.GetCookiesFrom(bakery));
            var tedT = new Thread(() => ted.GetCookiesFrom(bakery));
            var gregT = new Thread(() => greg.GetCookiesFrom(bakery));
            fredT.Start();
            tedT.Start();
            gregT.Start();

            while (true)
            {
                if (bakery.InStock) continue;

                Console.ReadKey();
                break;
            }
        }