internal sealed class SyncQueue<T>
{
private readonly Object m_lock = new object();
private readonly Queue<T> m_queue = new Queue<T>(); public void Enqueue(T item)
{
Monitor.Enter(m_lock);
m_queue.Enqueue(item);
Monitor.PulseAll(m_lock);
Monitor.Exit(m_lock);
} public T Dequeue()
{
Monitor.Enter(m_lock);
while (m_queue.Count == 0) Monitor.Wait(m_lock);
T item = m_queue.Dequeue();
Monitor.Exit(m_lock);
return item;
}
}Queue Thread
{
private readonly Object m_lock = new object();
private readonly Queue<T> m_queue = new Queue<T>(); public void Enqueue(T item)
{
Monitor.Enter(m_lock);
m_queue.Enqueue(item);
Monitor.PulseAll(m_lock);
Monitor.Exit(m_lock);
} public T Dequeue()
{
Monitor.Enter(m_lock);
while (m_queue.Count == 0) Monitor.Wait(m_lock);
T item = m_queue.Dequeue();
Monitor.Exit(m_lock);
return item;
}
}Queue Thread
{
private readonly Object m_lock = new object();
private readonly Queue<T> m_queue = new Queue<T>(); public void Enqueue(T item)
{
lock(m_lock)
{
m_queue.Enqueue(item);
}
} public T Dequeue()
{
lock(m_lock)
{
T item = m_queue.Dequeue();
return item;
}
}
}