Example #1
0
        public async Task LocalMutualExclusion_Serializes()
        {
            IScope <string> mutex = new LocalMutualExclusion <string>(EqualityComparer <string> .Default);

            var taskOne = mutex.WithScopeAsync(KeyOne, CancellationToken.None);
            var taskTwo = mutex.WithScopeAsync(KeyTwo, CancellationToken.None);

            var taskWaiting = mutex.WithScopeAsync(KeyOne, CancellationToken.None);

            using (await taskOne)
                using (await taskTwo)
                {
                    Assert.IsFalse(taskWaiting.IsCompleted);
                }

            using (await taskWaiting)
            {
            }
        }
Example #2
0
        public async Task LocalMutualExclusion_NoDeadlock()
        {
            IScope <string> mutex = new LocalMutualExclusion <string>(EqualityComparer <string> .Default);

            using (await mutex.WithScopeAsync(KeyOne, CancellationToken.None))
                using (await mutex.WithScopeAsync(KeyTwo, CancellationToken.None))
                {
                }

            using (await mutex.WithScopeAsync(KeyTwo, CancellationToken.None))
                using (await mutex.WithScopeAsync(KeyOne, CancellationToken.None))
                {
                }

            using (await mutex.WithScopeAsync(KeyOne, CancellationToken.None))
                using (await mutex.WithScopeAsync(KeyTwo, CancellationToken.None))
                {
                }
        }