Thread safe limited size queue
问题 I'm trying to write a subj queue, but I get deadlocks and other multithreading problems. I want to use Interlocked.CompareExchange to avoid lock usage. But this code doesn't work as expected: it just wipe entire Queue. What am I doing wrong here? public class FixedSizedQueue<T> : IEnumerable<T> { readonly ConcurrentQueue<T> _queue = new ConcurrentQueue<T>(); public int Limit { get; set; } public FixedSizedQueue(int limit) { Limit = limit; } public void Enqueue(T obj) { _queue.Enqueue(obj); if