public void TestPool()
        {
            var locker = new ReadWriteLockAsync();

            Task.Run(async() =>
            {
                await locker.EnterReadLock();
                await Task.Delay(1000);
                locker.ExitReadLock();
            });

            Task.Run(async() =>
            {
                await locker.EnterReadLock();
                await Task.Delay(1000);
                locker.ExitReadLock();
            });

            Task.Run(async() =>
            {
                await locker.EnterReadLock();
                await Task.Delay(1000);
                locker.ExitReadLock();
            });

            Task.Run(async() =>
            {
                await locker.EnterWriteLock();
                await Task.Delay(1000);
                locker.ExitWriteLock();
            });

            Task.Run(async() =>
            {
                await locker.EnterReadLock();
                await Task.Delay(1000);
                locker.ExitReadLock();
            });
        }
예제 #2
0
        public async Task <List <T> > GetPool()
        {
            try
            {
                await poolLocker.EnterReadLock();

                return(pool.Values.ToList());
            }
            finally
            {
                poolLocker.ExitReadLock();
            }
        }