[corlib] Add some missing memory barriers to the ConcurrentQueue methods to order...
authorZoltan Varga <vargaz@gmail.com>
Wed, 29 Oct 2014 21:08:42 +0000 (17:08 -0400)
committerZoltan Varga <vargaz@gmail.com>
Wed, 29 Oct 2014 21:14:10 +0000 (17:14 -0400)
mcs/class/corlib/System.Collections.Concurrent/ConcurrentQueue.cs

index ea8984394b46030245c00440b404dd639de7b2e9..958fc6153594c03f42b443fcb2f6959f907b6f76 100644 (file)
@@ -63,7 +63,7 @@ namespace System.Collections.Concurrent
                {
                        Node node = new Node ();
                        node.Value = item;
-                       
+
                        Node oldTail = null;
                        Node oldNext = null;
                        
@@ -71,6 +71,8 @@ namespace System.Collections.Concurrent
                        while (!update) {
                                oldTail = tail;
                                oldNext = oldTail.Next;
+
+                               Thread.MemoryBarrier ();
                                
                                // Did tail was already updated ?
                                if (tail == oldTail) {
@@ -104,6 +106,8 @@ namespace System.Collections.Concurrent
                                Node oldHead = head;
                                Node oldTail = tail;
                                oldNext = oldHead.Next;
+
+                               Thread.MemoryBarrier ();
                                
                                if (oldHead == head) {
                                        // Empty case ?
@@ -146,6 +150,8 @@ namespace System.Collections.Concurrent
                                }
 
                                result = oldNext.Value;
+
+                               Thread.MemoryBarrier ();
                                
                                //check if head has been updated
                                update = head != oldHead;