lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [11/12] lucenenet git commit: There was a race condition triggered by TestDocumentsWriterDeleteQueue.TestStressDeleteQueue. The value of Next changed after the Node original = Next; statement. This would cause the function to return false and end up corr
Date Tue, 17 Feb 2015 17:29:53 GMT
There was a race condition triggered by TestDocumentsWriterDeleteQueue.TestStressDeleteQueue.
The value of Next changed after the Node original = Next; statement. This would cause the
function to return false and end up corrupting the linked list. Comparing with cmp (the value
passed in) ensures that we properly return false if there is a change in Next.


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/1058ff75
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/1058ff75
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/1058ff75

Branch: refs/heads/master
Commit: 1058ff75d4081f7cef3891743b27d10699f95892
Parents: ad8ca53
Author: Chand2048 <Chand@Microsoft.com>
Authored: Fri Feb 13 16:47:37 2015 -0800
Committer: Itamar Syn-Hershko <itamar@code972.com>
Committed: Tue Feb 17 19:25:57 2015 +0200

----------------------------------------------------------------------
 src/Lucene.Net.Core/Index/DocumentsWriterDeleteQueue.cs | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/1058ff75/src/Lucene.Net.Core/Index/DocumentsWriterDeleteQueue.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/DocumentsWriterDeleteQueue.cs b/src/Lucene.Net.Core/Index/DocumentsWriterDeleteQueue.cs
index b4e621f..e5e79f3 100644
--- a/src/Lucene.Net.Core/Index/DocumentsWriterDeleteQueue.cs
+++ b/src/Lucene.Net.Core/Index/DocumentsWriterDeleteQueue.cs
@@ -1,3 +1,4 @@
+using Lucene.Net.Store;
 using Lucene.Net.Support;
 using System;
 using System.Threading;
@@ -294,6 +295,7 @@ namespace Lucene.Net.Index
             internal DeleteSlice(Node currentTail)
             {
                 Debug.Assert(currentTail != null);
+                Debug.Assert(currentTail.Next == null);
                 /*
                  * Initially this is a 0 length slice pointing to the 'current' tail of
                  * the queue. Once we update the slice we only need to assign the tail and
@@ -391,10 +393,8 @@ namespace Lucene.Net.Index
             {
                 // .NET port: Interlocked.CompareExchange(location, value, comparand) is
backwards from
                 // AtomicReferenceFieldUpdater.compareAndSet(obj, expect, update), so swapping
val and cmp.
-                // Also, it doesn't return bool if it was updated, so we need to compare
to see if
-                // original == comparand to determine whether to return true or false here.
-                Node original = Next;
-                return ReferenceEquals(Interlocked.CompareExchange(ref Next, val, cmp), original);
+                // Return true if the result of the CompareExchange is the same as the comparison.
+                return ReferenceEquals(Interlocked.CompareExchange(ref Next, val, cmp), cmp);
             }
         }
 


Mime
View raw message