public int RunTest() { int retCode = -10; rwls = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); threadCount = 0; oneThreadAccess = 0; retCode = DoTesting(); return retCode; }
public static void EnterExit() { using (ReaderWriterLockSlim rwls = new ReaderWriterLockSlim()) { Assert.False(rwls.IsReadLockHeld); rwls.EnterReadLock(); Assert.True(rwls.IsReadLockHeld); rwls.ExitReadLock(); Assert.False(rwls.IsReadLockHeld); Assert.False(rwls.IsUpgradeableReadLockHeld); rwls.EnterUpgradeableReadLock(); Assert.True(rwls.IsUpgradeableReadLockHeld); rwls.ExitUpgradeableReadLock(); Assert.False(rwls.IsUpgradeableReadLockHeld); Assert.False(rwls.IsWriteLockHeld); rwls.EnterWriteLock(); Assert.True(rwls.IsWriteLockHeld); rwls.ExitWriteLock(); Assert.False(rwls.IsWriteLockHeld); Assert.False(rwls.IsUpgradeableReadLockHeld); rwls.EnterUpgradeableReadLock(); Assert.False(rwls.IsWriteLockHeld); Assert.True(rwls.IsUpgradeableReadLockHeld); rwls.EnterWriteLock(); Assert.True(rwls.IsWriteLockHeld); rwls.ExitWriteLock(); Assert.False(rwls.IsWriteLockHeld); Assert.True(rwls.IsUpgradeableReadLockHeld); rwls.ExitUpgradeableReadLock(); Assert.False(rwls.IsUpgradeableReadLockHeld); Assert.True(rwls.TryEnterReadLock(0)); rwls.ExitReadLock(); Assert.True(rwls.TryEnterReadLock(Timeout.InfiniteTimeSpan)); rwls.ExitReadLock(); Assert.True(rwls.TryEnterUpgradeableReadLock(0)); rwls.ExitUpgradeableReadLock(); Assert.True(rwls.TryEnterUpgradeableReadLock(Timeout.InfiniteTimeSpan)); rwls.ExitUpgradeableReadLock(); Assert.True(rwls.TryEnterWriteLock(0)); rwls.ExitWriteLock(); Assert.True(rwls.TryEnterWriteLock(Timeout.InfiniteTimeSpan)); rwls.ExitWriteLock(); } }
public static void ReaderWriterLockSlimPerf() { ReaderWriterLockSlim rwLock = new ReaderWriterLockSlim(); foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) { rwLock.EnterReadLock(); rwLock.ExitReadLock(); } } }
public TypeKeyRepository( TypeKeyRepository copiedFrom ) { this._lock = new ReaderWriterLockSlim( LockRecursionPolicy.NoRecursion ); if ( copiedFrom == null ) { this._table = new Dictionary<RuntimeTypeHandle, object>(); } else { this._table = copiedFrom.GetClonedTable(); } }
public static void Dispose() { ReaderWriterLockSlim rwls; rwls = new ReaderWriterLockSlim(); rwls.Dispose(); Assert.Throws<ObjectDisposedException>(() => rwls.TryEnterReadLock(0)); Assert.Throws<ObjectDisposedException>(() => rwls.TryEnterUpgradeableReadLock(0)); Assert.Throws<ObjectDisposedException>(() => rwls.TryEnterWriteLock(0)); rwls.Dispose(); for (int i = 0; i < 3; i++) { rwls = new ReaderWriterLockSlim(); switch (i) { case 0: rwls.EnterReadLock(); break; case 1: rwls.EnterUpgradeableReadLock(); break; case 2: rwls.EnterWriteLock(); break; } Assert.Throws<SynchronizationLockException>(() => rwls.Dispose()); } }
public static void Ctor() { ReaderWriterLockSlim rwls; using (rwls = new ReaderWriterLockSlim()) { Assert.Equal(LockRecursionPolicy.NoRecursion, rwls.RecursionPolicy); } using (rwls = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion)) { Assert.Equal(LockRecursionPolicy.NoRecursion, rwls.RecursionPolicy); } using (rwls = new ReaderWriterLockSlim((LockRecursionPolicy)12345)) { Assert.Equal(LockRecursionPolicy.NoRecursion, rwls.RecursionPolicy); } using (rwls = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion)) { Assert.Equal(LockRecursionPolicy.SupportsRecursion, rwls.RecursionPolicy); } }
public static void InvalidTimeouts() { using (ReaderWriterLockSlim rwls = new ReaderWriterLockSlim()) { Assert.Throws<ArgumentOutOfRangeException>(() => rwls.TryEnterReadLock(-2)); Assert.Throws<ArgumentOutOfRangeException>(() => rwls.TryEnterUpgradeableReadLock(-3)); Assert.Throws<ArgumentOutOfRangeException>(() => rwls.TryEnterWriteLock(-4)); Assert.Throws<ArgumentOutOfRangeException>(() => rwls.TryEnterReadLock(TimeSpan.MaxValue)); Assert.Throws<ArgumentOutOfRangeException>(() => rwls.TryEnterUpgradeableReadLock(TimeSpan.MinValue)); Assert.Throws<ArgumentOutOfRangeException>(() => rwls.TryEnterWriteLock(TimeSpan.FromMilliseconds(-2))); } }
public SubHybridTree(sbyte levelDepth,Vector3 pos) : base(levelDepth) { position = pos+((Vector3.one*size)*0.5f); queuedPoints = new List<Vector3>(); queuedValues = new List<sbyte>(); rwValueLock = new ReaderWriterLockSlim(); rwQueueLock = new ReaderWriterLockSlim(); rwNodePosLock = new ReaderWriterLockSlim(); rwNodeRightLock = new ReaderWriterLockSlim(); //position = pos; }
internal LockEnumeratorWrapper(ReaderWriterLockSlim locker, IEnumerator <T> enumerator) : base(locker, enumerator) { }
protected DisposableLockBase(ReaderWriterLockSlim rwLock) { this.rwLock = rwLock; this.isDisposed = false; }
/// <summary> /// Initializes a new instance of the <see cref="T:ExitGames.Threading.UpgradeableReadLock"/> struct. /// </summary> /// <param name="syncObject">The reader writer lock</param> private UpgradeableReadLock(ReaderWriterLockSlim syncObject) { this.syncObject = syncObject; this.syncObject.EnterUpgradeableReadLock(); }
public WriteLockScope(ReaderWriterLockSlim @lock) { m_lock = @lock; m_lock.EnterWriteLock(); }
public RwLock() { this.rwLock = new ReaderWriterLockSlim(); }
public BinaryFileIntegerArray(string path, int size) { Lock = new ReaderWriterLockSlim(); context = new ReadWriteContext(this); int fileLength = size * sizeof(int); this.path = path; if (!File.Exists(path)) { File.WriteAllBytes(path, new byte[fileLength]); } }
public PerRequestCacheManager(IHttpContextAccessor httpContextAccessor) { _httpContextAccessor = httpContextAccessor; _locker = new ReaderWriterLockSlim(); }
static ParserLog() { ParserLog._readWriteLock = new ReaderWriterLockSlim(); }
/// <summary> /// Initializes a new instance of the <see cref="ReaderWriterSlimLock"/> class. /// </summary> /// <param name="lock">The reference to <see cref="ReaderWriterLockSlim"/>.</param> public ReaderWriterSlimLock(ReaderWriterLockSlim @lock) { this.@lock = @lock; }
/// <summary> /// Enters a critical section with <see cref="M:System.Threading.ReaderWriterLockSlim.TryEnterUpgradeableReadLock(System.Int32)"/> and returns a new instance of <see cref="T:ExitGames.Threading.WriteLock"/>. /// </summary> /// <param name="syncObject"> /// The reader writer lock. /// </param> /// <param name="millisecondsTimeout"> /// The timeout for <see cref="M:System.Threading.ReaderWriterLockSlim.TryEnterUpgradeableReadLock(System.Int32)"/> in milliseconds. /// </param> /// <returns>A <see cref="T:ExitGames.Threading.UpgradeableReadLock"/> that can be disposed to call <see cref="M:System.Threading.ReaderWriterLockSlim.ExitUpgradeableReadLock"/>. /// </returns> /// <exception cref="T:ExitGames.Threading.LockTimeoutException"> /// <see cref="M:System.Threading.ReaderWriterLockSlim.TryEnterUpgradeableReadLock(System.Int32)"/> returned false. ///</exception> public static IDisposable TryEnter(ReaderWriterLockSlim syncObject, int millisecondsTimeout) { return(new UpgradeableReadLock(syncObject, millisecondsTimeout)); }
/// <summary> /// Enters a critical section with <see cref="M:System.Threading.ReaderWriterLockSlim.EnterUpgradeableReadLock"/> and returns a new instance of <see cref="T:ExitGames.Threading.UpgradeableReadLock"/>. /// </summary> /// <param name="syncObject">The reader writer lock.</param> /// <returns> /// A <see cref="T:ExitGames.Threading.UpgradeableReadLock"/> that can be disposed to call <see cref="M:System.Threading.ReaderWriterLockSlim.ExitUpgradeableReadLock"/>. ///</returns> public static IDisposable Enter(ReaderWriterLockSlim syncObject) { return(new UpgradeableReadLock(syncObject)); }
public static void ReadersMayBeConcurrent() { using (Barrier barrier = new Barrier(2)) using (ReaderWriterLockSlim rwls = new ReaderWriterLockSlim()) { Assert.Equal(0, rwls.CurrentReadCount); Task.WaitAll( Task.Run(() => { rwls.EnterReadLock(); barrier.SignalAndWait(); // 1 Assert.True(rwls.IsReadLockHeld); barrier.SignalAndWait(); // 2 Assert.Equal(2, rwls.CurrentReadCount); barrier.SignalAndWait(); // 3 barrier.SignalAndWait(); // 4 rwls.ExitReadLock(); }), Task.Run(() => { barrier.SignalAndWait(); // 1 rwls.EnterReadLock(); barrier.SignalAndWait(); // 2 Assert.True(rwls.IsReadLockHeld); Assert.Equal(0, rwls.WaitingReadCount); barrier.SignalAndWait(); // 3 rwls.ExitReadLock(); barrier.SignalAndWait(); // 4 })); Assert.Equal(0, rwls.CurrentReadCount); } }
/// <summary> /// Creates a new ThreadSafeGenericList object. /// </summary> public ThreadSafeGenericList() { _items = new List <T>(); _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); }
static void Main(string[] args) { Options options; try { options = Options.FromCommandLine(args); } catch (Options.ParsingException ex) { LOGGER.Fatal(ex.Message); LOGGER.Info(Options.ShowUsage()); Environment.Exit(-1); return; } server = createDefaultPRServer(); mutex = new ReaderWriterLockSlim(); try { endPoint = new UdpClient(new IPEndPoint(options.EmulatorIP, options.EmulatorPort)); } catch (Exception ex) { LOGGER.Fatal("Unable to create UDP listener: " + ex.Message); Environment.Exit(-1); return; } for (int i = 0; i < 5; i++) { Thread thread = new Thread(() => ReporterWorker(options.BattlefieldIP, options.BattlefieldPort)) { IsBackground = false // make sure no thread keeps working even if this reached the end }; thread.Start(); } LOGGER.Info("GSEmulator ready at {0}:{1}!", options.EmulatorIP.ToString(), options.EmulatorPort); for (string line = Console.ReadLine(); line != null; line = Console.ReadLine()) { try { LOGGER.Trace("Parsing: '{0}'", line); Command command = Parser.Parse(line); mutex.EnterWriteLock(); command.Execute(ref server); } catch (Exception ex) { LOGGER.Warn(ex.ToString()); } finally { if (mutex.IsWriteLockHeld) { mutex.ExitWriteLock(); } } } LOGGER.Warn("Python PIPE was closed"); // Closing UDP Client // Causes worker threads to exit their while loop endPoint.Close(); LOGGER.Info("GSEmulator is shuting down..."); }
public DisposableWriteLock(ReaderWriterLockSlim rwLock) : base(rwLock) { this.Lock.EnterWriteLock(); }
/// <summary> /// Creates a new ThreadSafeSortedList object. /// </summary> public ThreadSafeSortedList() { _items = new SortedList <TK, TV>(); _lock = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion); }
public UpgradeableReadLockHelper( ReaderWriterLockSlim readerWriterLock ) { readerWriterLock.EnterUpgradeableReadLock(); this.readerWriterLock = readerWriterLock; }
// Set methodExecutor, returning an error string if there are any problems (ambiguous match, etc.). public void DetermineMethodInfo(CodeActivityMetadata metadata, MruCache <MethodInfo, Func <object, object[], object> > funcCache, ReaderWriterLockSlim locker, ref MethodExecutor methodExecutor) { bool returnEarly = false; MethodExecutor oldMethodExecutor = methodExecutor; methodExecutor = null; if (string.IsNullOrEmpty(this.MethodName)) { metadata.AddValidationError(SR.ActivityPropertyMustBeSet("MethodName", this.Parent.DisplayName)); returnEarly = true; } Type targetType = this.TargetType; // If TargetType and the type of TargetObject are both set, it's an error. if (targetType != null && this.TargetObject != null && !this.TargetObject.IsEmpty) { metadata.AddValidationError(SR.TargetTypeAndTargetObjectAreMutuallyExclusive(this.Parent.GetType().Name, this.Parent.DisplayName)); returnEarly = true; } // If TargetType was set, look for a static method. If TargetObject was set, look for an instance method. They can't both be set. BindingFlags bindingFlags = this.TargetType != null ? staticBindingFlags : instanceBindingFlags; string bindingType = bindingFlags == staticBindingFlags ? staticString : instanceString; if (targetType == null) { if (this.TargetObject != null && !this.TargetObject.IsEmpty) { targetType = this.TargetObject.ArgumentType; } else { metadata.AddValidationError(SR.OneOfTwoPropertiesMustBeSet("TargetObject", "TargetType", this.Parent.GetType().Name, this.Parent.DisplayName)); returnEarly = true; } } // We've had one or more constraint violations already if (returnEarly) { return; } // Convert OutArgs and InOutArgs to out/ref types before resolution Type[] parameterTypes = Parameters.Select(argument => argument.Direction == ArgumentDirection.In ? argument.ArgumentType : argument.ArgumentType.MakeByRefType()) .ToArray(); Type[] genericTypeArguments = this.GenericTypeArguments.ToArray(); InheritanceAndParamArrayAwareBinder methodBinder = new InheritanceAndParamArrayAwareBinder(targetType, genericTypeArguments, this.Parent); // It may be possible to know (and check) the resultType even if the result won't be assigned anywhere. // Used 1.) for detecting async pattern, and 2.) to make sure we selected the correct MethodInfo. Type resultType = this.ResultType; if (this.RunAsynchronously) { int formalParamCount = parameterTypes.Length; Type[] beginMethodParameterTypes = new Type[formalParamCount + 2]; for (int i = 0; i < formalParamCount; i++) { beginMethodParameterTypes[i] = parameterTypes[i]; } beginMethodParameterTypes[formalParamCount] = typeof(AsyncCallback); beginMethodParameterTypes[formalParamCount + 1] = typeof(object); Type[] endMethodParameterTypes = { typeof(IAsyncResult) }; this.beginMethod = Resolve(targetType, "Begin" + this.MethodName, bindingFlags, methodBinder, beginMethodParameterTypes, genericTypeArguments, true); if (this.beginMethod != null && !this.beginMethod.ReturnType.Equals(typeof(IAsyncResult))) { this.beginMethod = null; } this.endMethod = Resolve(targetType, "End" + this.MethodName, bindingFlags, methodBinder, endMethodParameterTypes, genericTypeArguments, true); if (this.endMethod != null && resultType != null && !TypeHelper.AreTypesCompatible(this.endMethod.ReturnType, resultType)) { metadata.AddValidationError(SR.ReturnTypeIncompatible(this.endMethod.ReturnType.Name, MethodName, targetType.Name, this.Parent.DisplayName, resultType.Name)); this.endMethod = null; return; } if (this.beginMethod != null && this.endMethod != null && this.beginMethod.IsStatic == this.endMethod.IsStatic) { if (!(oldMethodExecutor is AsyncPatternMethodExecutor) || !((AsyncPatternMethodExecutor)oldMethodExecutor).IsTheSame(this.beginMethod, this.endMethod)) { methodExecutor = new AsyncPatternMethodExecutor(metadata, this.beginMethod, this.endMethod, this.Parent, this.TargetType, this.TargetObject, this.Parameters, this.Result, funcCache, locker); } else { methodExecutor = new AsyncPatternMethodExecutor((AsyncPatternMethodExecutor)oldMethodExecutor, this.TargetType, this.TargetObject, this.Parameters, this.Result); } return; } } MethodInfo result; try { result = Resolve(targetType, this.MethodName, bindingFlags, methodBinder, parameterTypes, genericTypeArguments, false); } catch (AmbiguousMatchException) { metadata.AddValidationError(SR.DuplicateMethodFound(targetType.Name, bindingType, MethodName, this.Parent.DisplayName)); return; } if (result == null) { metadata.AddValidationError(SR.PublicMethodWithMatchingParameterDoesNotExist(targetType.Name, bindingType, MethodName, this.Parent.DisplayName)); return; } else if (resultType != null && !TypeHelper.AreTypesCompatible(result.ReturnType, resultType)) { metadata.AddValidationError( SR.ReturnTypeIncompatible(result.ReturnType.Name, MethodName, targetType.Name, this.Parent.DisplayName, resultType.Name)); return; } else { this.syncMethod = result; if (this.RunAsynchronously) { if (!(oldMethodExecutor is AsyncWaitCallbackMethodExecutor) || !((AsyncWaitCallbackMethodExecutor)oldMethodExecutor).IsTheSame(this.syncMethod)) { methodExecutor = new AsyncWaitCallbackMethodExecutor(metadata, this.syncMethod, this.Parent, this.TargetType, this.TargetObject, this.Parameters, this.Result, funcCache, locker); } else { methodExecutor = new AsyncWaitCallbackMethodExecutor((AsyncWaitCallbackMethodExecutor)oldMethodExecutor, this.TargetType, this.TargetObject, this.Parameters, this.Result); } } else if (!(oldMethodExecutor is SyncMethodExecutor) || !((SyncMethodExecutor)oldMethodExecutor).IsTheSame(this.syncMethod)) { methodExecutor = new SyncMethodExecutor(metadata, this.syncMethod, this.Parent, this.TargetType, this.TargetObject, this.Parameters, this.Result, funcCache, locker); } else { methodExecutor = new SyncMethodExecutor((SyncMethodExecutor)oldMethodExecutor, this.TargetType, this.TargetObject, this.Parameters, this.Result); } } }
public WriteLockHelper( ReaderWriterLockSlim readerWriterLock ) { readerWriterLock.EnterWriteLock(); this.readerWriterLock = readerWriterLock; }
/// <summary> /// Initializes a new instance of the <see cref="WriteLockDisposable"/> class. /// </summary> /// <param name="rwLock">The rw lock.</param> public WriteLockDisposable(ReaderWriterLockSlim rwLock) { _rwLock = rwLock; _rwLock.EnterWriteLock(); }
public ObservableCollectionSafe() { _coll = new Collection <T>(); _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); }
public EvenCartLocker(ReaderWriterLockSlim @lock) { _lock = @lock; _lock.EnterWriteLock(); }
public InMemoryEnvironmentStateRepository() { _lock = new ReaderWriterLockSlim(); _environmentState = new EnvironmentState(-1, new List <ToggleState>()); }
public static void QueueTask(int LinePriority,Task task,Task post) { if (taskPoolObject == null) { taskPoolObject = new GameObject("_taskPoolObject"); taskPoolObject.AddComponent<TaskPool>(); JobQueue = new List<Job>(); postJobQueue = new List<Job>(); rwLock = new ReaderWriterLockSlim(); tasks = new List<Task>(); if (workers == null) { workers = new ThreadWorker[8]; for (int i = 0; i < 8; i++) { workers[i] = new ThreadWorker(i); workers[i].workerThread = new Thread(new ThreadStart(workers[i].Work)); workers[i].workerThread.Start(); } //Debug.Log("started "+workers.Count.ToString()+" Workers"); } } Job InsertJob = new Job(task,post,LinePriority); rwLock.EnterUpgradeableReadLock(); try { if (JobQueue == null) { rwLock.EnterWriteLock(); try { JobQueue = new List<Job>(); } finally { rwLock.ExitWriteLock(); } } if (JobQueue != null) { rwLock.EnterWriteLock(); try { JobQueue.Add(InsertJob); } finally { rwLock.ExitWriteLock(); } } } finally { rwLock.ExitUpgradeableReadLock(); } }
public void Dispose() { _lock?.Dispose(); _lock = null; }
public SubPathfinder(WorldTree target) { rwLock = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion); pathQueue = new List<AIPath>(); outsideQueue = new List<AIPath>(); syncedTree = new WorldTree(target.GetMaxLevelDepth()); targetTree = target; }
public UpgradeableReadLockDisposable(ReaderWriterLockSlim rwLock) { this._rwLock = rwLock; }
public static void DeadlockAvoidance() { using (ReaderWriterLockSlim rwls = new ReaderWriterLockSlim()) { rwls.EnterReadLock(); Assert.Throws<LockRecursionException>(() => rwls.EnterReadLock()); Assert.Throws<LockRecursionException>(() => rwls.EnterUpgradeableReadLock()); Assert.Throws<LockRecursionException>(() => rwls.EnterWriteLock()); rwls.ExitReadLock(); rwls.EnterUpgradeableReadLock(); rwls.EnterReadLock(); Assert.Throws<LockRecursionException>(() => rwls.EnterReadLock()); rwls.ExitReadLock(); Assert.Throws<LockRecursionException>(() => rwls.EnterUpgradeableReadLock()); rwls.EnterWriteLock(); Assert.Throws<LockRecursionException>(() => rwls.EnterWriteLock()); rwls.ExitWriteLock(); rwls.ExitUpgradeableReadLock(); rwls.EnterWriteLock(); Assert.Throws<LockRecursionException>(() => rwls.EnterReadLock()); Assert.Throws<LockRecursionException>(() => rwls.EnterUpgradeableReadLock()); Assert.Throws<LockRecursionException>(() => rwls.EnterWriteLock()); rwls.ExitWriteLock(); } using (ReaderWriterLockSlim rwls = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion)) { rwls.EnterReadLock(); Assert.Throws<LockRecursionException>(() => rwls.EnterWriteLock()); rwls.EnterReadLock(); Assert.Throws<LockRecursionException>(() => rwls.EnterUpgradeableReadLock()); rwls.ExitReadLock(); rwls.ExitReadLock(); rwls.EnterUpgradeableReadLock(); rwls.EnterReadLock(); rwls.EnterUpgradeableReadLock(); rwls.ExitUpgradeableReadLock(); rwls.EnterReadLock(); rwls.ExitReadLock(); rwls.ExitReadLock(); rwls.EnterWriteLock(); rwls.EnterWriteLock(); rwls.ExitWriteLock(); rwls.ExitWriteLock(); rwls.ExitUpgradeableReadLock(); rwls.EnterWriteLock(); rwls.EnterReadLock(); rwls.ExitReadLock(); rwls.EnterUpgradeableReadLock(); rwls.ExitUpgradeableReadLock(); rwls.EnterWriteLock(); rwls.ExitWriteLock(); rwls.ExitWriteLock(); } }
private WriteLock(ReaderWriterLockSlim lockSlim) { _LockSlim = lockSlim; _LockSlim.EnterWriteLock(); }
public static void InvalidExits(LockRecursionPolicy policy) { using (ReaderWriterLockSlim rwls = new ReaderWriterLockSlim(policy)) { Assert.Throws<SynchronizationLockException>(() => rwls.ExitReadLock()); Assert.Throws<SynchronizationLockException>(() => rwls.ExitUpgradeableReadLock()); Assert.Throws<SynchronizationLockException>(() => rwls.ExitWriteLock()); rwls.EnterReadLock(); Assert.Throws<SynchronizationLockException>(() => rwls.ExitUpgradeableReadLock()); Assert.Throws<SynchronizationLockException>(() => rwls.ExitWriteLock()); rwls.ExitReadLock(); rwls.EnterUpgradeableReadLock(); Assert.Throws<SynchronizationLockException>(() => rwls.ExitReadLock()); Assert.Throws<SynchronizationLockException>(() => rwls.ExitWriteLock()); rwls.ExitUpgradeableReadLock(); rwls.EnterWriteLock(); Assert.Throws<SynchronizationLockException>(() => rwls.ExitReadLock()); Assert.Throws<SynchronizationLockException>(() => rwls.ExitUpgradeableReadLock()); rwls.ExitWriteLock(); using (Barrier barrier = new Barrier(2)) { Task t = Task.Factory.StartNew(() => { rwls.EnterWriteLock(); barrier.SignalAndWait(); barrier.SignalAndWait(); rwls.ExitWriteLock(); }, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default); barrier.SignalAndWait(); Assert.Throws<SynchronizationLockException>(() => rwls.ExitWriteLock()); barrier.SignalAndWait(); t.GetAwaiter().GetResult(); } } }
private ReadLock(ReaderWriterLockSlim lockSlim) { _LockSlim = lockSlim; _LockSlim.TryEnterReadLock(TimeSpan.FromSeconds(ReadTimeout)); }
public static void WritersAreMutuallyExclusiveFromWriters() { using (Barrier barrier = new Barrier(2)) using (ReaderWriterLockSlim rwls = new ReaderWriterLockSlim()) { Task.WaitAll( Task.Run(() => { rwls.EnterWriteLock(); barrier.SignalAndWait(); Assert.True(rwls.IsWriteLockHeld); barrier.SignalAndWait(); rwls.ExitWriteLock(); }), Task.Run(() => { barrier.SignalAndWait(); Assert.False(rwls.TryEnterWriteLock(0)); Assert.False(rwls.IsReadLockHeld); barrier.SignalAndWait(); })); } }
public WriterLockZone(ReaderWriterLockSlim rwl) : this(new WriterLockWrapper(rwl)) { }
public static void WriterToUpgradeableReaderChain() { using (AutoResetEvent are = new AutoResetEvent(false)) using (ReaderWriterLockSlim rwls = new ReaderWriterLockSlim()) { rwls.EnterWriteLock(); Task t = Task.Factory.StartNew(() => { Assert.False(rwls.TryEnterUpgradeableReadLock(TimeSpan.FromMilliseconds(10))); Task.Run(() => are.Set()); // ideally this won't fire until we've called EnterReadLock, but it's a benign race in that the test will succeed either way rwls.EnterUpgradeableReadLock(); rwls.ExitUpgradeableReadLock(); }, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default); are.WaitOne(); rwls.ExitWriteLock(); t.GetAwaiter().GetResult(); } }
public void Clone(Connection connection) { this.SqlDatabase = connection.SqlDatabase; this.SqlServerType = connection.SqlServerType; this.m_connection = connection.m_connection; this.m_bGlobal = connection.m_bGlobal; this.m_lock = connection.m_lock; this.m_nLockTimeout = connection.m_nLockTimeout; this.m_nOpenCount = connection.m_nOpenCount; }
private UpdateLock(ReaderWriterLockSlim lockSlim) { _LockSlim = lockSlim; _LockSlim.EnterUpgradeableReadLock(); }
public WriteLock(ReaderWriterLockSlim locks) : base(locks) { Locks.GetWriteLock(_Locks); }
public WriterLockWrapper(ReaderWriterLockSlim rwl) : base(rwl) { }
public ConcurrentEnumerator(IEnumerable <T> inner, ReaderWriterLockSlim @lock) { this._lock = @lock; this._lock.EnterReadLock(); this._inner = inner.GetEnumerator(); }
public ConcurrentList(int capacity) { this._lock = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion); this._list = new List <T>(capacity); }
public ConcurrentList(IEnumerable <T> items) { this._lock = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion); this._list = new List <T>(items); }
public TypeKeyRepository( Dictionary<RuntimeTypeHandle, object> table ) { this._lock = new ReaderWriterLockSlim( LockRecursionPolicy.NoRecursion ); this._table = table; }
protected AbstractReaderWriterLockWrapper(ReaderWriterLockSlim rwl) { BaseLock = rwl; }