Здравствуйте,
Спасибо заранее за ответы.
Есть wrapper:
public class SyncQueue {
object sync_obj = new Object();
Queue inner_queue = Queue.Synchronized( new Queue() );
WaitHandle[] h_wakeup = new WaitHandle[ 2 ] {
// see the constructor comments
null,
// awakes awaiting threads when the queue is not empty
// initially it's non-signaled
new AutoResetEvent( false )
};
public virtual void PushBack( object obj ) {
// the inner_queue is synchronized, so we do not worry
// when adding a new object
inner_queue.Enqueue( obj );
}
public virtual object PopFront() {
object result = null;
// ensuring that no more than 1 object will be awaken
lock ( sync_obj ) {
// awaiting either the termination event or the event,
// signaling this thread to wake up
int h_no = WaitHandle.WaitAny( h_wakeup );
// if the termination event has not occured do pop()
if ( h_no != 0 ) result = inner_queue.Dequeue();
}
// return null if the termination event has occured or
// return object if the queue has been updated
return result;
}
// h_terminate - is a handle which is non-signaled state
// by default; it is to terminate a thread awaiting a
// new request being queued; it is designed to terminate
// awaiting threads when the server is stopped
public SyncQueue( WaitHandle h_terminate ) {
this.h_wakeup[ 0 ] = h_terminate;
}
}
Когда из какого-то thread'а вызывается PopFront() и очередь пуста, thread уходит в wait, 4то правильно, НО! при этом CPU usage — 100% и комп умирает как на бесконечном цикле.... Никто не сталкивался??