public static void Enqueue(TopicMessage msg) { QueueBase queue = new QueueBase(); queue = _dic.GetOrAdd(msg.Topic, queue); queue.Enqueue(msg.Content); Interlocked.Increment(ref _in); }
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(); } }
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(); } }