Exemple #1
0
        public SleazyBar(int knights, int wineCapacity, int plateCapacity)
        {
            this.knights       = knights;
            this.wineCapacity  = wineCapacity;
            this.plateCapacity = plateCapacity;
            this.wine          = wineCapacity;

            resources = new Resource[knights];
            dishes    = new bool[knights];
            waiting   = new bool[knights];
            qWaiting  = new ConditionVariable[knights];

            for (int k = 0; k < knights; k++)
            {
                // For simplicity, let's assume that wine is always even - indexed.
                var type = k % 2 == 0 ? ResourceType.Wine : ResourceType.Cucumbers;

                resources[k] = new Resource(type);
                if (type == ResourceType.Cucumbers)
                {
                    resources[k].Count = plateCapacity;
                }

                qWaiting[k] = new ConditionVariable();
            }
        }
Exemple #2
0
        public Rostrum(int knights)
        {
            this.knights = knights;

            states     = new RostrumState[knights];
            waiting    = new bool[knights];
            listening  = new bool[knights];
            qWaiting   = new ConditionVariable[knights];
            qListening = new ConditionVariable[knights];

            for (int k = 0; k < knights; k++)
            {
                states[k]     = RostrumState.NotTalking;
                qWaiting[k]   = new ConditionVariable();
                qListening[k] = new ConditionVariable();
            }
        }