示例#1
0
        public M TryConsume()
        {
            MsgHolder observed, newValue = null;

            do
            {
                observed = msgHolder;
                if (observed != null && observed.lives > 0)
                {
                    newValue = new MsgHolder(observed.msg, observed.lives - 1);
                }
                else
                {
                    return(null);
                }
            } while (Interlocked.CompareExchange(ref msgHolder, newValue, observed) != observed);

            return(newValue.msg);
        }
示例#2
0
 public void Publish(M m, int lvs)
 {
     msgHolder = new MsgHolder(m, lvs);
 }