Пример #1
0
        public void TestTinyLock_Lock()
        {
            var       tl    = new TinyLock();
            const int count = 100000000;
            Stopwatch sw    = new Stopwatch();

            sw.Start();

            for (int x = 0; x < count; x++)
            {
                using (tl.Lock());
                using (tl.Lock());
                using (tl.Lock());
                using (tl.Lock());
                using (tl.Lock());
                using (tl.Lock());
                using (tl.Lock());
                using (tl.Lock());
                using (tl.Lock());
                using (tl.Lock());
            }
            sw.Stop();

            Console.WriteLine((count * 10.0 / sw.Elapsed.TotalSeconds / 1000000));
        }
Пример #2
0
        public void TestContention()
        {
            m_value = 0;
            m_sync  = new TinyLock();
            m_event = new ManualResetEvent(true);

            for (int x = 0; x < 16; x++)
            {
                ThreadPool.QueueUserWorkItem(Adder);
            }

            Thread.Sleep(100);
            m_event.Set();

            while (m_value < 16 * max)
            {
                Console.WriteLine(m_value);
                Thread.Sleep(1000);
            }

            Console.WriteLine(m_value);
        }