static async Task TestAwaitableCriticalSectionAsync(int iterations, bool isContended) { var mutex = new AwaitableCriticalSection(); if (isContended) { var waits = new Task<IDisposable>[iterations]; using (await mutex.EnterAsync()) for (int i = 0; i < iterations; i++) waits[i] = mutex.EnterAsync(); for (int i = 0; i < iterations; i++) using (await waits[i]) { } } else { for (int i = 0; i < iterations; i++) using (await mutex.EnterAsync()) { } } }
public Disposable(AwaitableCriticalSection owner) { _owner = owner; }