public bool Acquire(int id, StCancelArgs cargs)
 {
     m.Enter();
     try {
         if (permits >= id)
         {
             permits -= id;
             return(true);
         }
         while (true)
         {
             int lastTime = Environment.TickCount;
             cv.Wait(cargs);
             if (permits >= id)
             {
                 permits -= id;
                 return(true);
             }
             if (!cargs.AdjustTimeout(ref lastTime))
             {
                 return(false);
             }
         }
     } finally {
         m.Exit();
     }
 }
        public bool Offer(T data, StCancelArgs cargs)
        {
            m.Enter();
            try {
                if (buffer.Count < capacity)
                {
                    buffer.Enqueue(data);
                    cv.PulseAll();
                    return(true);
                }
                while (true)
                {
                    int lastTime = Environment.TickCount;
                    cv.Wait(cargs);

                    if (buffer.Count < capacity)
                    {
                        buffer.Enqueue(data);
                        cv.PulseAll();
                        return(true);
                    }
                    if (!cargs.AdjustTimeout(ref lastTime))
                    {
                        return(false);
                    }
                }
            } finally {
                m.Exit();
            }
        }