Explorar o código

Merge pull request #220 from Reactive-Extensions/observerbase-fix

Add Volatile Read/Write around isStopped for thread safety
Brendan Forster %!s(int64=9) %!d(string=hai) anos
pai
achega
7a4ee85ab5

+ 2 - 2
Rx.NET/Source/System.Reactive.Core/Reactive/ObserverBase.cs

@@ -29,7 +29,7 @@ namespace System.Reactive
         /// <param name="value">Next element in the sequence.</param>
         public void OnNext(T value)
         {
-            if (isStopped == 0)
+            if (Volatile.Read(ref isStopped) == 0)
                 OnNextCore(value);
         }
 
@@ -98,7 +98,7 @@ namespace System.Reactive
         {
             if (disposing)
             {
-                isStopped = 1;
+                Volatile.Write(ref isStopped, 1);
             }
         }