private static long CheckMutualExclusion(ILock @lock, int count, int cyclesCount) { var buckets = new long[count]; var finished = new bool[count]; var total = 0L; ThreadId.ZeroOut(); var threads = Enumerable.Range(0, count).Select(i => { return(new Thread(() => { for (var j = 0; j < cyclesCount; j++) { @lock.Lock(); buckets[i]++; total++; @lock.Unlock(); } finished[i] = true; })); }); foreach (var thread in threads) { thread.Start(); } while (finished.Any(f => !f)) { } return(total); }