예제 #1
0
        public static void Enqueue(TopicMessage msg)
        {
            QueueBase queue = new QueueBase();

            queue = _dic.GetOrAdd(msg.Topic, queue);
            queue.Enqueue(msg.Content);
            Interlocked.Increment(ref _in);
        }
예제 #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();
            }
        }
예제 #3
0
        public void TestEnqueue(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());
                }
            }))
                          .ToArray();

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