Пример #1
0
 /// <summary>
 /// Send a message to the channel with unlimited timeout.
 /// </summary>
 /// <param name="item">The object to send. Any objects are allowed to be transfered through this channel.</param>
 /// <remarks>This member is thread-safe.</remarks>
 public void Send(object item)
 {
     try { empty.Acquire(); }
     catch (System.Threading.ThreadInterruptedException e)
     {
         DumpItem(item);
         throw e;
     }
     queue.Enqueue(item);
     full.Release();
 }
Пример #2
0
        /// <summary>
        /// Block until another thread calls the same method.
        /// </summary>
        public void RendezVous()
        {
            bool s;

            lock (this)
            {
                s       = select;
                select ^= true;
            }
            if (s)
            {
                Console.WriteLine("RV: AA");
                right.Release();
                Console.WriteLine("RV: AB");
                left.Acquire();
                Console.WriteLine("RV: AC");
            }
            else
            {
                Console.WriteLine("RV: BA");
                left.Release();
                Console.WriteLine("RV: BB");
                right.Acquire();
                Console.WriteLine("RV: BC");
            }
        }