Exemplo n.º 1
0
        // read element from the queue
        public T readElem()
        {
            Monitor.Enter(mObj);

            while (!mCanRead)
            {
                Monitor.Wait(mObj);
            }

            ElemItem <T> elm = mLstReadWrite[0];
            T            ret = elm.GetElem();

            mLstReadWrite.RemoveAt(0);
            mLstCapcity.Add(elm);

            mCanWrite = true;
            if (mLstCapcity.Count >= mSize)
            {
                mCanRead = false;
            }
            Monitor.PulseAll(mObj);

            Monitor.Exit(mObj);

            return(ret);
        }
Exemplo n.º 2
0
        // write element into the queue
        public void writeElem(T Elm)
        {
            Monitor.Enter(mObj);

            while (!mCanWrite)
            {
                Monitor.Wait(mObj);
            }

            ElemItem <T> elm = mLstCapcity[0];

            mLstCapcity.RemoveAt(0);

            elm.SetElem(Elm);

            mLstReadWrite.Add(elm);
            mCanRead = true;

            if (mLstCapcity.Count <= 0)
            {
                mCanWrite = false;
            }

            Monitor.PulseAll(mObj);

            Monitor.Exit(mObj);
        }