private int Allocate(int len) { int alen; while ((alen = TryAllocate (len)) == 0) { // Wait until somebody reads data try { Monitor.Wait (thisLock); } catch { closed = true; dataEvent.Set (); throw; } } return alen; }