diff Implab/Parallels/MTQueue.cs @ 71:1714fd8678ef

code cleanup
author cin
date Wed, 03 Sep 2014 18:34:02 +0400
parents ee04e1fa78da
children 4f20870d0816
line wrap: on
line diff
--- a/Implab/Parallels/MTQueue.cs	Wed Sep 03 11:57:43 2014 +0400
+++ b/Implab/Parallels/MTQueue.cs	Wed Sep 03 18:34:02 2014 +0400
@@ -44,27 +44,27 @@
                     // this is the last element,
                     // then try to update the tail
                     if (first != Interlocked.CompareExchange(ref m_last, null, first)) {
-                        // this is a race condition
+                        // this is the race condition
                         if (m_last == null)
                             // the queue is empty
                             return false;
-                        // tail has been changed, than we need to restart
+                        // tail has been changed, we need to restart
                         continue; 
                     }
 
                     // tail succesfully updated and first.next will never be changed
-                    // other readers will fail due to inconsistency m_last != m_fist, but m_first.next == null
-                    // but the writer may update the m_first since the m_last is null
+                    // other readers will fail due to inconsistency m_last != m_fist && m_first.next == null
+                    // however the parallel writer may update the m_first since the m_last is null
 
-                    // so we need to fix inconsistency by setting m_first to null, but if it already has been
-                    // updated by a writer then we should just give up
+                    // so we need to fix inconsistency by setting m_first to null or if it has been
+                    // updated by the writer already then we should just to give up
                     Interlocked.CompareExchange(ref m_first, null, first);
                     break;
 
                 } else {
-                        if (first == Interlocked.CompareExchange(ref m_first, next, first))
-                            // head succesfully updated
-                            break;
+                    if (first == Interlocked.CompareExchange(ref m_first, next, first))
+                        // head succesfully updated
+                        break;
                 }
             } while (true);