using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace ch14_4
{
    class Producer
    {
        private Buffer sharedLocation;
        private Random randomSleepTime;
        // constructor
        public Producer(Buffer shared, Random random)
        {
            sharedLocation = shared;
            randomSleepTime = random;
        } // end constructor
        // store values 1-5 in object sharedLocation
        public void Produce()
        {
            // sleep for random interval up to 3000 milliseconds
            // then set sharedLocation's Buffer property
            for (int count = 1; count <= 5; count++)
            {
                Thread.Sleep(randomSleepTime.Next(1, 3)); 
                sharedLocation.Buffer = count;
            } // end for
            CommonClass.output += "\n";
            CommonClass.output += Thread.CurrentThread.Name + " done producing";
            CommonClass.output += "\n " + Thread.CurrentThread.Name + " Terminating";
        } // end method Produce
    }
}
