public void run()
        {
            CSTimer tim = new CSTimer();

            toConsole.write("Starting ... \n");
            while (true)
            {
                toConsole.write("Thinking ... \n");
                if (id > 0)
                {
                    tim.sleep(3000);
                }
                else
                {
                    // Philosopher 0, has a 0.1 second think
                    tim.sleep(100);
                }

                toConsole.write("Need a chicken ...\n");
                service.write(id);
                int gotOne = (int)deliver.read();
                if (gotOne > 0)
                {
                    toConsole.write("Eating ... \n");
                    tim.sleep(2000);
                    toConsole.write("Brrrp ... \n");
                }
                else
                {
                    toConsole.write("                   Oh dear No chickens left \n");
                }
            }
        }
        public void run()
        {
            CSTimer tim  = new CSTimer();
            int     tick = 0;

            while (true)
            {
                toConsole.write("Time: " + tick + " \n");
                tim.sleep(1000);
                tick = tick + 1;
            }
        }
Beispiel #3
0
        /**
         * The main body of this process.
         */
        public void run()
        {
            CSTimer tim = new CSTimer();

            while (true)
            {
                Object o = In.read();
                //Debug.WriteLine("Fixed delay sleeping for " + delayTime);
                tim.sleep(delayTime);
                Out.write(o);
            }
        }
Beispiel #4
0
        public void run()
        {
            CSTimer timer = new CSTimer();
            int     tick  = 0;

            while (true)
            {
                Console.WriteLine("[TICK] " + tick);
                timer.sleep(1000);
                tick++;
            }
        }
Beispiel #5
0
        public void run()
        {
            CSTimer timer  = new CSTimer();
            long    second = 1000; // JCSP timer units are milliseconds
            int     busy   = id + 1;

            while (true)
            {
                timer.sleep(busy * second); // application specific work
                Console.WriteLine("Player " + id + " at the barrier ...");
                barrier.sync();
                Console.WriteLine("\t\t\t... Player " + id + " over the barrier");
                busy = (nPlayers + 1) - busy; // just to make it more interesting
            }
        }
Beispiel #6
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()
        {
            Random  rng   = new Random();
            CSTimer timer = new CSTimer();

            while (true)
            {
                Console.WriteLine("\t\tReindeer" + number + ": on holiday ... wish you were here, :)");
                timer.sleep(holidayTime + rng.Next(holidayTime));
                Console.WriteLine("\t\tReindeer " + number + ": back from holiday ... ready for work, :(");
                stable.sync();
                harness.write(number);
                harnessed.read();
                Console.WriteLine("\t\tReindeer " + number + ": delivering toys ... la-di-da-di-da-di-da, :)");
                returned.read();
                Console.WriteLine("\t\tReindeer " + number + ": all toys delivered ... want a holiday, :(");
                unharness.read();
            }
        }
        public void run()
        {
            Random  rng   = new Random();
            CSTimer timer = new CSTimer();

            while (true)
            {
                Console.WriteLine("\tElf " + number + ": working, :)");
                timer.sleep(workingTime + rng.Next(workingTime));
                needToConsult.write(number);
                int group = (int)joinGroup.read();
                groups[group].fallInto();
                // process will wait until flushed by vestibule
                // it is guaranteed by vestibule that three Elf proceses will be started
                consult.write(number);
                Console.WriteLine("\tElf " + number + ": need to consult Santa, :(");
                consulting.read();
                Console.WriteLine("\tElf " + number + ": about these toys ... ???");
                negotiating.write(1);
                consulted.read();
                Console.WriteLine("\tElf " + number + ": OK ... we will build it, bye, :(");
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Run Writers started.");

            int nChannels = 1;

            Console.WriteLine("Please enter number of writers per channel");
            int nWritersPerChannel = Int32.Parse(Console.ReadLine());
            int nMessages          = 2;

            Console.WriteLine("Please enter writer ID");
            int writerID = Int32.Parse(Console.ReadLine());


            Console.WriteLine("Please enter IP address for this node.");
            var writersChannelNodeIP = Console.ReadLine();

            Console.WriteLine("Please enter IP address for Reader.");
            var readerNodeIP = Console.ReadLine();


            var readerNodeAddr = new TCPIPNodeAddress(readerNodeIP, 3300);
            var fromReader     = NetChannel.net2one();

            var writersChannelNodesAddresses = new TCPIPNodeAddress(writersChannelNodeIP, 3300);

            Node.getInstance().init(writersChannelNodesAddresses);

            var readersChannelNumberForThisWriter = Int32.Parse("5" + (writerID - 1));
            var writers2network = NetChannel.any2net(readerNodeAddr, readersChannelNumberForThisWriter);

            Console.WriteLine("writers2network location = " + writers2network.getLocation().ToString());

            Console.WriteLine("Informing reader that Writer" + writerID + " is ready and sending its IP");
            //writers2network.write(GetLocalIPAddress.ConvertLocalIPAddressToString()); //use while all nodes are on different machines
            writers2network.write(writersChannelNodeIP); //use for local loopback addresses

            CSTimer timer = new CSTimer();

            timer.sleep(2000);
            Console.WriteLine("Waiting for the signal from Reader...");
            fromReader.read();

            Console.WriteLine("Read signal from Reader");

            //====================== Running the test
            StressedWriterPerformance[] writers = new StressedWriterPerformance[nChannels * nWritersPerChannel];

            for (int channel = 0; channel < nChannels; channel++)
            {
                for (int i = 0; i < nWritersPerChannel; i++)
                {
                    writers[(channel * nWritersPerChannel) + i] =
                        new StressedWriterPerformance(writers2network, channel, i, writerID);
                    writerID++;
                }
            }

            for (int i = 0; i < 100; i++)
            {
                new CSPParallel(
                    new IamCSProcess[]
                {
                    new CSPParallel(writers),
                }
                    ).run();
            }

            Console.WriteLine("Finished all");
        }
Beispiel #10
0
        public void run()
        {
            const int   REINDEER = 0;
            const int   ELVES    = 1;
            Random      rng      = new Random();
            CSTimer     timer    = new CSTimer();
            Alternative santaAlt = new Alternative(new Guard[] { stable, consult as Guard });

            openForBusiness.write(1);
            int index = -1;

            while (true)
            {
                index = santaAlt.priSelect();
                int[] id = new int[9]; //size of the array must be provided. For loops no greater than 9 - Karol Pasierb

                switch (index)
                {
                case REINDEER:
                    Console.WriteLine("Santa: ho-ho-ho ... the reindeer are back");
                    for (int i = 0; i < 9; i++)
                    {
                        ;
                        id[i] = (int)harness.read();
                        Console.WriteLine("Santa: harnessing reindeer " + id[i] + " ...");
                    }

                    Console.WriteLine("Santa: mush mush ...");
                    for (int i = 0; i < 9; i++)
                    {
                        harnessed.write(1);
                    }

                    // simulate time to undertake present deliveries
                    timer.sleep(deliveryTime + rng.Next(deliveryTime));
                    Console.WriteLine("Santa: woah ... we are back home");
                    for (int i = 0; i < 9; i++)
                    {
                        returned.write(1);
                    }

                    for (int i = 0; i < 9; i++)
                    {
                        Console.WriteLine("Santa: unharnessing reindeer " + id[i]);
                        unharnessList[id[i]].write(1);
                    }

                    break;

                case ELVES:
                    id[0] = (int)consult.read();
                    for (int i = 1; i < 3; i++)
                    {
                        id[i] = (int)consult.read();
                    }

                    Console.WriteLine("Santa: ho-ho-ho ... some elves are here!");
                    for (int i = 0; i < 3; i++)
                    {
                        consulting[id[i]].write(1);
                        Console.WriteLine("Santa: hello elf " + id[i] + " ...");
                    }

                    for (int i = 0; i < 3; i++)
                    {
                        negotiating.read();
                    }

                    Console.WriteLine("Santa: consulting with elves ...");
                    timer.sleep(consultationTime + rng.Next(consultationTime));
                    Console.WriteLine("Santa: OK, all done - thanks!");
                    for (int i = 0; i < 3; i++)
                    {
                        consulted[id[i]].write(1);
                        Console.WriteLine("Santa: goodbye elf " + id[i] + " ...");
                    }

                    consultationOver.write(1);
                    break;
                }
            }
        }