Example #1
0
        public void run()
        {
            CSTimer timer         = new CSTimer();
            Random  rnd           = new Random();
            int     randomTimeout = rnd.Next(1, 10) * n * 500;

            timeout = timer.read() + randomTimeout;
            Debug.WriteLine(n + "Process timeout " + randomTimeout);

            Object x = input.read();

            Console.WriteLine(n + "Read value" + x);
            while (true)
            {
                x = input.read();
                Console.WriteLine(n + "Read value" + x);

                //output.write(x);
                long currentTime = timer.read();
                if (timeout <= currentTime) //if timeout should occur now
                {
                    timeout = timer.read() + rnd.Next(1, 10) * 500;
                    Debug.WriteLine(n + "Process timout ppassed " + randomTimeout);
                    output.write(n + "For Input guard" + x + "0000000");
                    timer.after(timeout);
                    output.write(n + "Finished");
                    timeout = timer.read() + rnd.Next(1, 10) * n * 500;
                }
            }
        }
        public void run()
        {
            long    halfSecond = 500;
            long    second     = 1000;
            CSTimer tim        = new CSTimer();
            long    timeout    = tim.read();

            while (true)
            {
                timeout += 5000;
                tim.after(timeout);
                Console.WriteLine("                    <== now every second");
                reset.Out().write(second);
                timeout += 5000;
                tim.after(timeout);
                Console.WriteLine("                    <== now every half second");
                reset.Out().write(halfSecond);
            }
        }
        public void run()
        {
            CSTimer timer   = new CSTimer();
            long    timeout = timer.read(); // read the (absolute) time once only

            while (true)
            {
                N++;
                Out.write(N);
                timeout += interval;  // set the next (absolute) timeOut
                timer.after(timeout); // wait until that (absolute) timeOut
            }
        }
Example #4
0
        public void run()
        {
            CSTimer timer = new CSTimer();

            while (true)
            {
                //Console.WriteLine("Inside GPrint timer");
                if (delay != 0)
                {
                    timer.after(timer.read() + delay);
                    Console.WriteLine(heading.Split(' ')[0] + " \t" + inChannel.read());
                }
            }
        }
Example #5
0
        public void run()
        {
            CSTimer tim      = new CSTimer();
            int     CHICKENS = 4;

            toConsole.write("Starting ... \n");
            while (true)
            {
                toConsole.write("Cooking ... \n"); // cook 4 chickens;
                tim.after(tim.read() + 2000);      // this takes 2 seconds to cook;
                toConsole.write(CHICKENS + "chickens ready ... \n");
                supply.write(CHICKENS);
                toConsole.write("Taking chickens to Canteen ... \n");
                supply.write(0);
            }
        }
        public void run()
        {
            //initialize internal arrays of 2-dimensional array
            int[][] n = new int[c.Length][];
            for (int i = 0; i < n.Length; i++)
            {
                n[i] = new int[nWritersPerChannel];
            }

            //setup variables
            const int      initialWait = 3000;
            int            iterations = nMessages * nChannels * nWritersPerChannel;
            long           t0 = 0, t1 = 0, microseconds = 0;
            Alternative    alt               = new Alternative(c);
            CSTimer        timer             = new CSTimer();
            int            channelFairSelect = 0;
            StressedPacket stressedPacket;
            var            csv = new StringBuilder();


            //set the timer to wait for 5 seconds to make sure that all the readers are idle in writing state
            Console.WriteLine("Waiting 3 seconds...");
            timer.after(initialWait + timer.read());
            Console.WriteLine("Waiting is over. Measuring time");


            //perform read and measure the time
            t0 = CSTimer.CurrentTimeMillis();
            for (int i = 0; i < iterations; i++)
            {
                channelFairSelect = alt.fairSelect();
                stressedPacket    = (StressedPacket)c[channelFairSelect].read();
                n[channelFairSelect][stressedPacket.writer] = stressedPacket.n;
            }

            t1           = CSTimer.CurrentTimeMillis();
            microseconds = (t1 - t0) * 1000;
            if (microseconds > 0)
            {
                Console.WriteLine("Reading time for " + iterations + " iterations: " + microseconds);
                var newLine = string.Format("{0},{1},{2},{3},{4}", nChannels, nWritersPerChannel, nMessages, iterations,
                                            microseconds);
                csv.AppendLine(newLine);
                File.AppendAllText(@"d:\\NetworkedstressedAlt_Test" + nChannels + "x" + nWritersPerChannel + ".csv",
                                   csv.ToString());
            }
        }
        public void run()
        {
            CSTimer timer = new CSTimer();

            int n_chickens;

            Console.WriteLine("            Chef    : starting ... ");
            while (true)
            {
                // cook 4 chickens
                Console.WriteLine("            Chef    : cooking ... ");
                timer.after(timer.read() + 2000); // this takes 3 seconds to cook
                n_chickens = 4;
                Console.WriteLine("            Chef    : " + n_chickens + " chickens, ready-to-go ... ");
                supply.write(n_chickens); // supply the chickens
                supply.write(0);          // wait till they're set down
            }
        }
Example #8
0
        public void run()
        {
            int currentFactor = 0;
            var timer         = new CSTimer();
            var timeout       = timer.read();

            while (true)
            {
                timeout = timeout + testInterval;
                timer.after(timeout);
                suspend.write(0);
                currentFactor = (int)factor.read();

                currentFactor = currentFactor + addition;
                timer.sleep(computeInterval);

                injector.write(currentFactor);
            }
        }
        public void run()
        {
            Guard[]   canteenGuards = { supply as Guard, service as Guard };
            Boolean[] precondition  = { true, false };
            var       canteenAlt    = new Alternative(canteenGuards);

            const int SUPPLY  = 0;
            const int SERVICE = 1;

            CSTimer tim      = new CSTimer();
            int     chickens = 0;

            toConsole.write("Canteen : starting ... \n");

            while (true)
            {
                precondition[SERVICE] = (chickens > 0);
                if (chickens == 0)
                {
                    toConsole.write("Waiting for chickens ...\n");
                }

                switch (canteenAlt.fairSelect(precondition))
                {
                case SUPPLY:
                    int value = (int)(long)supply.read();
                    toConsole.write("Chickens on the way ...\n");
                    tim.after(tim.read() + 3000);
                    chickens = chickens + value;
                    toConsole.write(chickens + " chickens now available ...\n");
                    supply.read();
                    break;

                case SERVICE:
                    int id = (int)(long)service.read();
                    chickens = chickens - 1;
                    toConsole.write("chicken ready for Philosoper " + id + " ... " + chickens +
                                    " chickens left \n");
                    deliver.write(1);
                    break;
                }
            }
        }
Example #10
0
        public void run()
        {
            CSTimer tim = new CSTimer();

            Console.WriteLine("      Philosopher " + id + "  : starting ... ");
            while (true)
            {
                // everyone, bar Philosopher 0, has a little think
                if (id > 0)
                {
                    tim.after(tim.read() + 3000); // thinking
                }

                // want chicken
                Console.WriteLine("      Philosopher " + id + "  : gotta eat ... ");
                service.write(0);
                deliver.read();
                Console.WriteLine("      Philosopher " + id + "  : mmm ... that's good ... ");
            }
        }
        public void run()
        {
            Alternative alt = new Alternative(new Guard[] { supply, service });

            Boolean[] precondition = { true, false };
            const int SUPPLY       = 0;
            const int SERVICE      = 1;

            CSTimer timer = new CSTimer();

            int nChickens = 0;

            Console.WriteLine("            Canteen : starting ... ");
            while (true)
            {
                precondition[SERVICE] = (nChickens > 0);
                switch (alt.fairSelect(precondition))
                {
                case SUPPLY:
                    int value = (int)supply.read();     // new batch of chickens from the Chef
                    Console.WriteLine("            Canteen : ouch ... make room ... this dish is very hot ... ");
                    timer.after(timer.read() + 3000);   // this takes 3 seconds to put down
                    nChickens += value;
                    Console.WriteLine("            Canteen : more chickens ... " +
                                      nChickens + " now available ... ");
                    supply.read();     // let the Chef get back to cooking
                    break;

                case SERVICE:
                    service.read();     // Philosopher wants a chicken
                    Console.WriteLine("      Canteen : one chicken coming down ... " +
                                      (nChickens - 1) + " left ... ");
                    deliver.write(1);     // serve one chicken
                    nChickens--;
                    break;
                }
            }
        }
        public void run()
        {
            int innerCycleTime = n * start;

            CSTimer tim     = new CSTimer();
            long    timeout = tim.read();

            while (true)
            {
                int interval = start;
                while (interval >= stop)
                {
                    int innerCycles = innerCycleTime / interval;
                    for (int i = 0; i < innerCycles; i++)
                    {
                        Out.write(interval);
                        timeout += (long)interval;
                        tim.after(timeout);
                    }

                    interval /= 2;
                }
            }
        }