Ejemplo n.º 1
0
        public void TestDequeue(QueueBase <string> queue)
        {
            var threads = Enumerable
                          .Range(0, _threadCount)
                          .Select(
                n => new Thread(
                    () =>
            {
                var left = _iterations;
                while (left > 0)
                {
                    string res;
                    if (queue.TryDequeue(out res))
                    {
                        left--;
                    }
                }
            }))
                          .ToArray();

            foreach (var thread in threads)
            {
                thread.Start();
            }
            foreach (var thread in threads)
            {
                thread.Join();
            }
        }
Ejemplo n.º 2
0
        public void TestEnqueueDequeue(QueueBase <string> queue, int threadCount)
        {
            var threads = Enumerable
                          .Range(0, threadCount)
                          .Select(
                n => new Thread(
                    () =>
            {
                for (var i = 0; i < _iterations; i++)
                {
                    queue.Enqueue(i.ToString());
                }
            }))
                          .Concat(new[] { new Thread(() =>
                {
                    var left = _iterations;
                    while (left > 0)
                    {
                        string res;
                        if (queue.TryDequeue(out res))
                        {
                            left--;
                        }
                    }
                }) })
                          .ToArray();

            foreach (var thread in threads)
            {
                thread.Start();
            }
            foreach (var thread in threads)
            {
                thread.Join();
            }
        }