/// <summary> /// Helper to ensure the lock object is created before first use. /// </summary> private void EnsureLockObjectCreated() { Contract.Ensures(m_lock != null); Contract.Ensures(m_condition != null); if (m_lock == null) { Lock newObj = new Lock(); Interlocked.CompareExchange(ref m_lock, newObj, null); // failure is benign.. someone else won the race. } if (m_condition == null) { Condition newCond = new Condition(m_lock); Interlocked.CompareExchange(ref m_condition, newCond, null); } }