public class Info_Queue<_Info>
...{
Queue<_Info> _queue;
Event_Trigger _produce;
Event_Trigger _consume;
Unique _locker = new Unique();
public Info_Queue(int size)
...{
this._queue = new Queue<_Info>(size);
this._produce = new Event_Trigger(size);
this._consume = new Event_Trigger();
}
public void Push(_Info item)
...{
this._produce.Wait();
this._locker.Lock();
&nb
this._locker.UnLock();
this._consume.Post();
}
public _Info Pop()
...{
this._consume.Wait();
_Info item = default(_Info);
this._locker.Lock();
item = this._queue.Dequeue();
this._locker.UnLock();
this._produce.Post();
return item;
}
public int Count()
...{
return this._queue.Count;
}
public void Clear()
...{ this._queue.Clear();
this._locker.Close();
this._produce.Close();
this._consume.Close();
}
}下篇文章我將展示如何使用它構造一個對象池.