예제 #1
0
        //Adding wheels to jondas thread
        public static void AddWheelsFactory()
        {
            //loop to run the factory line
            bool run = true;

            while (run == true)
            {
                //variable to check if factory line has a jonda to work on later
                Jonda jonda = null;

                //locks to make manipulating of data thread safe
                if (Monitor.TryEnter(_jondasWithWheelsLock, -1))
                {
                    JondasWithWheels++;
                    Monitor.Exit(_jondasWithWheelsLock);
                }

                //times this work takes
                Thread.Sleep(FactorySettings.WheelAddingTime);

                //gets the jonda with body to put wheels on
                while (jonda == null)
                {
                    if (Monitor.TryEnter(Conveyers.BodiesPaintedConveyerLock, -1))
                    {
                        jonda = Conveyers.BodiesPaintedConveyer;
                        Monitor.Exit(Conveyers.BodiesPaintedConveyerLock);
                    }

                    if (jonda == null)
                    {
                        Thread.Sleep(FactorySettings.NoWorkWaitTime);
                    }
                }

                //puts the wheels on the jonda
                for (int i = 0; i < 4; i++)
                {
                    jonda.Wheels[i] = new Wheel();
                }

                //puts the jonda with body and wheels onto the next conveyor
                if (Monitor.TryEnter(Conveyers.MissingEngineJondaLock, -1))
                {
                    Conveyers.MissingEngineJondas = jonda;
                    Monitor.Exit(Conveyers.MissingEngineJondaLock);
                }

                //checks if work is done for today
                if (Monitor.TryEnter(_jondasWithWheelsLock, -1))
                {
                    if (JondasWithWheels == 250)
                    {
                        run = false;
                    }
                    Monitor.Exit(_jondasWithWheelsLock);
                }
            }
        }
예제 #2
0
        //Painting bodies thread
        public static void BodyPaintingFactory()
        {
            //loop to run the factory line
            bool run = true;

            while (run == true)
            {
                //variable to check if factory line has a body to work on later
                Jonda jonda = null;

                //locks to make manipulating of data thread safe
                if (Monitor.TryEnter(_bodiesPaintedLock, -1))
                {
                    BodiesPainted++;
                    Monitor.Exit(_bodiesPaintedLock);
                }

                //times this work takes
                Thread.Sleep(FactorySettings.BodyPaintingTime);

                //gets body to paint
                while (jonda == null)
                {
                    if (Monitor.TryEnter(Conveyers.BodiesAssembledConveyerLock, -1))
                    {
                        jonda = Conveyers.BodiesAssembledConveyer;
                        Monitor.Exit(Conveyers.BodiesAssembledConveyerLock);
                    }

                    if (jonda == null)
                    {
                        Thread.Sleep(FactorySettings.NoWorkWaitTime);
                    }
                }

                //random color for the car
                jonda.Body.Color = _colors[_rnd.Next(0, _colors.Length)];

                //puts the painted body on next conveyor
                if (Monitor.TryEnter(Conveyers.BodiesPaintedConveyerLock, -1))
                {
                    Conveyers.BodiesPaintedConveyer = jonda;
                    Monitor.Exit(Conveyers.BodiesPaintedConveyerLock);
                }

                //checks if work is done for today
                if (Monitor.TryEnter(_bodiesPaintedLock, -1))
                {
                    if (BodiesPainted == 250)
                    {
                        run = false;
                    }
                    Monitor.Exit(_bodiesPaintedLock);
                }
            }
        }
예제 #3
0
        //adding engine to jondas thread
        //
        public static void AddEngineFactory()
        {
            bool run = true;

            while (run == true)
            {
                //variable to check if factory line has a jonda to work on later
                Jonda jonda = null;

                //locks to make manipulating of data thread safe
                if (Monitor.TryEnter(_jondasDoneLock, -1))
                {
                    JondasDone++;
                    Monitor.Exit(_jondasDoneLock);
                }

                //times this work takes
                Thread.Sleep(FactorySettings.EngineAddingTime);

                //gets the jonda with body to add engine to it
                while (jonda == null)
                {
                    if (Monitor.TryEnter(Conveyers.MissingEngineJondaLock, -1))
                    {
                        jonda = Conveyers.MissingEngineJondas;
                        Monitor.Exit(Conveyers.MissingEngineJondaLock);
                    }

                    if (jonda == null)
                    {
                        Thread.Sleep(FactorySettings.NoWorkWaitTime);
                    }
                }

                //puts the engine in the jonda
                jonda.Motor = new Motor();

                //puts the jonda with body, whells and engine finished conveyor
                if (Monitor.TryEnter(Conveyers.JondasDoneLock, -1))
                {
                    Conveyers.JondasDone = jonda;
                    Monitor.Exit(Conveyers.JondasDoneLock);
                }

                //checks if work is done for today
                if (Monitor.TryEnter(_jondasDoneLock, -1))
                {
                    if (JondasDone == 250)
                    {
                        run = false;
                    }
                    Monitor.Exit(_jondasDoneLock);
                }
            }
        }
예제 #4
0
        //Assembling bodies thread
        public static void BodyAssemblingFactory()
        {
            //loop to run the factory line
            bool run = true;

            while (run == true)
            {
                //variable to check if factory line has a body to work on later
                Body body = null;

                //locks to make manipulating of data thread safe
                if (Monitor.TryEnter(_bodiesAssembledLock, -1))
                {
                    BodiesAssembled++;
                    Monitor.Exit(_bodiesAssembledLock);
                }

                //times this work takes
                Thread.Sleep(FactorySettings.BodyAssembleTime);

                //gets plates to assemble a body
                while (body == null)
                {
                    if (Monitor.TryEnter(Conveyers.BodyPlatesConveyerLock, -1))
                    {
                        body = Conveyers.BodyPlatesConveyer;
                        Monitor.Exit(Conveyers.BodyPlatesConveyerLock);
                    }

                    if (body == null)
                    {
                        Thread.Sleep(FactorySettings.NoWorkWaitTime);
                    }
                }

                //finds out what kind of jonda to create and creates it
                Jonda jonda = null;
                if (Monitor.TryEnter(_createCarTypeLock, -1))
                {
                    if (CarsCreated != 120)
                    {
                        jonda = new Car();
                        CarsCreated++;
                    }
                    else if (MinisCreated != 40)
                    {
                        jonda = new Mini();
                        MinisCreated++;
                    }
                    else if (MaxisCreated != 50)
                    {
                        jonda = new Maxi();
                        MaxisCreated++;
                    }
                    else if (SportsCreated != 40)
                    {
                        jonda = new Sport();
                        SportsCreated++;
                    }

                    jonda.Body = body;

                    Monitor.Exit(_createCarTypeLock);
                }

                //puts the assembled jonda onto the next conveyor
                if (Monitor.TryEnter(Conveyers.BodiesAssembledConveyerLock, -1))
                {
                    Conveyers.BodiesAssembledConveyer = jonda;
                    Monitor.Exit(Conveyers.BodiesAssembledConveyerLock);
                }

                //checks if work is done for today
                if (Monitor.TryEnter(_bodiesAssembledLock, -1))
                {
                    if (BodiesAssembled == 250)
                    {
                        run = false;
                    }
                    Monitor.Exit(_bodiesAssembledLock);
                }
            }
        }