diff --git a/Sally7/RequestExecutor/ConcurrentRequestExecutor.cs b/Sally7/RequestExecutor/ConcurrentRequestExecutor.cs index 8ca4daa..f1aae66 100644 --- a/Sally7/RequestExecutor/ConcurrentRequestExecutor.cs +++ b/Sally7/RequestExecutor/ConcurrentRequestExecutor.cs @@ -192,7 +192,7 @@ private class JobPool : IDisposable { private readonly Channel _jobIdPool; private readonly Request[] _requests; - private volatile bool _disposed; + private bool _disposed; public JobPool(int maxNumberOfConcurrentRequests) { @@ -212,7 +212,7 @@ public JobPool(int maxNumberOfConcurrentRequests) public void Dispose() { - _disposed = true; + Volatile.Write(ref _disposed, true); _jobIdPool.Writer.Complete(); } @@ -220,7 +220,7 @@ public void Dispose() public void ReturnJobId(int jobId) { - if (!_jobIdPool.Writer.TryWrite(jobId) && !_disposed) + if (!_jobIdPool.Writer.TryWrite(jobId) && !Volatile.Read(ref _disposed)) { Sally7Exception.ThrowFailedToReturnJobIDToPool(jobId); }