Пример #1
0
        public void GarbageCollection()
        {
            JVSTMSystem.StartGC();
            var box1 = new VBox <int>(0);

            for (var i = 0; i < 100; i++)
            {
                JVSTMSystem.Atomic(t =>
                {
                    box1.Put(t, i);
                });
            }

            var box2 = new VBox <int>(0);

            for (var i = 0; i < 100; i++)
            {
                JVSTMSystem.Atomic(t =>
                {
                    box2.Put(t, i);
                });
            }


            Thread.Sleep(10);
            Assert.AreEqual(1, box1.GetNrBodies());
            Assert.AreEqual(1, box2.GetNrBodies());
        }
Пример #2
0
        public void GarbageCollectionConcurrent()
        {
            var box1 = new VBox <int>(0);
            var t1   = new Thread(() =>
            {
                for (var i = 0; i < 100; i++)
                {
                    JVSTMSystem.Atomic(t =>
                    {
                        box1.Put(t, i);
                    });
                }
            });

            var t2 = new Thread(() =>
            {
                for (var i = 0; i < 100; i++)
                {
                    JVSTMSystem.Atomic(t =>
                    {
                        box1.Put(t, i);
                    });
                }
            });

            t1.Start();
            t2.Start();

            t1.Join();
            t2.Join();

            Assert.AreEqual(1, box1.GetNrBodies());
        }
Пример #3
0
        static void Main(string[] args)
        {
            //Test1();
            //Test2();
            //Test3();
            //Test4();
            //TestRetry();
            //TestRetry2();
            //SingleItemBufferTest();
            //QueueTest();
            //AtomicLockTest();
            //DinningPhilosophersTest();
            //OrElseNestingTest();
            //OrElseTest();
            //OrElseNestingTest2();
            //OrElseNestingTest3();
            //var dining = new DiningPhilosopher();
            //dining.Start();
            //TestMSQueue();

            //JVSpeedTest();
            //JVSpeedTest();

            //var dinning = new JVDining();
            //dinning.Start();

            //JVTest();
            //JVConcurrentTest();

            /*
             * for (int j = 0; j < 100; j++)
             * {
             *  var result = new VBox<int>(0);
             *
             *  var t1 = new Thread(() =>
             *  {
             *      for (int i = 0; i < 1000; i++)
             *      {
             *          JVSTMSystem.Atomic((transaction) =>
             *          {
             *              result.Put(transaction, result.Read(transaction) + 1);
             *          });
             *      }
             *
             *
             *  });
             *
             *  var t2 = new Thread(() =>
             *  {
             *      for (int i = 0; i < 1000; i++)
             *      {
             *          JVSTMSystem.Atomic((transaction) =>
             *          {
             *              result.Put(transaction, result.Read(transaction) + 1);
             *          });
             *      }
             *
             *  });
             *
             *  t1.Start();
             *  t2.Start();
             *
             *  t1.Join();
             *  t2.Join();
             *
             *  var res = JVSTMSystem.Atomic((transaction) => result.Read(transaction));
             *  if (res != 2000)
             *  {
             *      Console.WriteLine("Error: " + res);
             *  }
             * }*/

            JVSTMSystem.StartGC();
            var result = new VBox <int>(0);

            var t1 = new Thread(() =>
            {
                for (int i = 0; i < 1000; i++)
                {
                    JVSTMSystem.Atomic((transaction) =>
                    {
                        result.Put(transaction, result.Read(transaction) + 1);
                    });
                }
            });

            var t2 = new Thread(() =>
            {
                for (int i = 0; i < 1000; i++)
                {
                    JVSTMSystem.Atomic((transaction) =>
                    {
                        result.Put(transaction, result.Read(transaction) + 1);
                    });
                }
            });

            t1.Start();
            t2.Start();

            t1.Join();
            t2.Join();
            Thread.Sleep(10);
            Console.WriteLine(result.GetNrBodies());
            Console.WriteLine("Done");
            Console.ReadKey();
        }