Ejemplo n.º 1
0
        public void CountMax()
        {
            var queue = new LLQueue <int>(Enumerable.Range(0, 100));

            Assert.AreEqual(100, queue.CountUntil(200));
            Assert.AreEqual(100, queue.CountUntil(100));
            Assert.AreEqual(50, queue.CountUntil(50));
            Assert.AreEqual(0, queue.CountUntil(0));
            queue.Clear();
            Assert.IsTrue(queue.IsEmpty);
        }
Ejemplo n.º 2
0
        public void RacingClears()
        {
            int cores = CoreCount();

            if (cores < 2)
            {
                cores = 2;
            }
            var threads = new Thread[cores];
            var queue   = new LLQueue <int>();
            int done    = 0;

            threads[0] = new Thread(() =>
            {
                for (int x = 0; x != 1000000; ++x)
                {
                    queue.Enqueue(x);
                }
                Interlocked.Increment(ref done);
            });
            for (int i = 1; i != cores; ++i)
            {
                threads[i] = new Thread(() =>
                {
                    while (done == 0)
                    {
                        for (int x = 0; x != 1000; ++x)
                        {
                            queue.Clear();
                        }
                    }
                });
            }
            for (int i = 0; i < cores; ++i)
            {
                threads[i].Start();
            }
            for (int i = 0; i < cores; ++i)
            {
                threads[i].Join();
            }
            Assert.IsTrue(queue.IsEmpty);
        }
Ejemplo n.º 3
0
 public void RacingClears()
 {
     int cores = CoreCount();
     if(cores < 2)
         cores = 2;
     var threads = new Thread[cores];
     var queue = new LLQueue<int>();
     int done = 0;
     threads[0] = new Thread(() =>
                                 {
                                     for(int x = 0; x != 1000000; ++x)
                                         queue.Enqueue(x);
                                     Interlocked.Increment(ref done);
                                 });
     for(int i = 1; i != cores; ++i)
     {
         threads[i] = new Thread(() =>
                                 {
                                     while(done == 0)
                                         for(int x = 0; x != 1000; ++x)
                                             queue.Clear();
                                 });
     }
     for(int i = 0; i < cores; ++i)
         threads[i].Start();
     for(int i = 0; i < cores; ++i)
         threads[i].Join();
     Assert.IsTrue(queue.IsEmpty);
 }
Ejemplo n.º 4
0
 public void CountMax()
 {
     var queue = new LLQueue<int>(Enumerable.Range(0, 100));
     Assert.AreEqual(100, queue.CountUntil(200));
     Assert.AreEqual(100, queue.CountUntil(100));
     Assert.AreEqual(50, queue.CountUntil(50));
     Assert.AreEqual(0, queue.CountUntil(0));
     queue.Clear();
     Assert.IsTrue(queue.IsEmpty);
 }