Browse Source

Add Volatile Read/Write around isStopped for thread safety

Oren Novotny 9 years ago
parent
commit
1dfa9d6ea4
1 changed files with 2 additions and 2 deletions
  1. 2 2
      Rx.NET/Source/System.Reactive.Core/Reactive/ObserverBase.cs

+ 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);
             }
         }