상속: Channel
예제 #1
0
            public void CheckQueues()
            {
                for (int i = 0; i < TRIALS; i++)
                {
                    int idx = BlockingQueue.Select(_queues, 5000);
                    Assert.IsFalse(idx == -1, "Timeout check");
                    BlockingQueue b = (BlockingQueue)_queues[idx];
                    bool          timedout;
                    object        val = b.Dequeue(0, out timedout);
                    Assert.IsFalse(timedout, "Dequeue didn't time out");
                    Assert.AreEqual(val, idx, "Dequeue matches index");
                }
                //Any future selects *should* timeout
                int idx2 = BlockingQueue.Select(_queues, 500);

                Assert.AreEqual(idx2, -1, "Did timeout");
            }
예제 #2
0
        /**
         * This method is not defined if there are other Dequeues pending
         * on any of these Queues.  REPEAT: if you are using Select you
         * cannot be doing Dequeues in another thread on any of these Queues.
         *
         * Tests seem to show that mono has a problem if there are more than 64
         * queues that we are waiting on, so this can't scale to huge numbers.
         *
         * @param queues a list of non-null BlockingQueue objects.
         * @param timeout how long to wait in milliseconds
         * @return the index into the list of a queue that is ready to Dequeue, -1 there is a timeout
         */
        public static int Select(IList queues, int timeout)
        {
            WaitHandle[] wait_handles = new WaitHandle[queues.Count];
            int          idx          = 0;

            foreach (BlockingQueue q in queues)
            {
                wait_handles[idx] = q._re;
                idx++;
            }
            idx = WaitHandle.WaitAny(wait_handles, timeout, true);
            if (idx == WaitHandle.WaitTimeout)
            {
                return(-1);
            }
            //Reset the AutoResetEvent
            BlockingQueue t = (BlockingQueue)queues[idx];

            t._re.Set();
            return(idx);
        }
예제 #3
0
 public ReaderState(BlockingQueue q, ArrayList all)
 {
     _q    = q;
     _list = all;
 }
예제 #4
0
 public WriterState(BlockingQueue q, ArrayList all, int runs)
 {
     _q    = q;
     _list = all;
     _runs = runs;
 }