public ThreadQueueItem pop_front()
        {
            Debug.Assert(size() > 0);
            ThreadQueueItem ret = buffer[tail];

            buffer[tail] = ThreadQueueItem.makeNull();
            tail         = (tail + 1) & mask;
            return(ret);
        }
        public void run()
        {
            while (stillRunning)
            {
                const int         maxMsgCnt = 8;
                ThreadQueueItem[] thq       = new ThreadQueueItem[maxMsgCnt];
                //int actualFromQueue = timeoutToUse == TimeOutNever ? popFrontFromThisThreadQueue(thq, maxMsgCnt) : popFrontFromThisThreadQueue(thq, maxMsgCnt, timeoutToUse / 1000);
                int nextTimeout     = getNextTimeout(0);
                int actualFromQueue = msgQueue.pop_front(thq, nextTimeout);

                for (int i = 0; i < actualFromQueue; ++i)
                {
                    Debug.Assert(thq[i].recipientID < nodes.Count);                               // current version limitation: just a single node per thread
                    Debug.Assert(thq[i].msgType == ThreadQueueItem.ThreadQueueItemType.GlobalMQ); // current version limitation
                    nodes[thq[i].recipientID].processMessagesAndOrTimeout(thq[i].msg);
                }

                foreach (NodeBase each in nodes)
                {
                    each.processMessagesAndOrTimeout(null);
                }
            }
        }
        public void push_back(ThreadQueueItem it)
        {
            //if the queue is full, just throw
            lock (mx)
            {
                while (coll.is_full() && stillRunning)
                {
                    Monitor.Wait(mx);
                }

                if (!stillRunning)
                {
                    return;
                }

                Debug.Assert(!coll.is_full());
                coll.push_back(it);
                int sz = coll.size();
                hwmsize = Math.Max(hwmsize, sz);

                Monitor.Pulse(mx);
            }//unlocking mx
        }
 public void push_back(ThreadQueueItem t)
 {
     Debug.Assert(size() < maxsz);
     buffer[head] = t;
     head         = (head + 1) & mask;
 }
 public void postMessage(BufferT msg)
 {
     msgQueue.push_back(ThreadQueueItem.makeGlobalMq(msg, recipientID));
 }