public class Channel{ T datum; volatile bool emptyflag = true; public void Write(T v) { lock (this) { while (!emptyflag) { Kiwi.NoUnroll(); Monitor.Wait(this); } datum = v; emptyflag = false; Monitor.PulseAll(this); } } public T Read() { T r; lock (this) { while (emptyflag) { Kiwi.NoUnroll(); Monitor.Wait(this); } emptyflag = true; r = datum; Monitor.PulseAll(this); } return r; } } }