Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r201:6b3036be4bb8
Date: 2013-06-20 10:14 +0200
http://bitbucket.org/pypy/stmgc/changeset/6b3036be4bb8/

Log:    Revert a part of 9507e1b05a3c: it's not the first time I mess this
        up. Add a comment.

diff --git a/c4/demo2.c b/c4/demo2.c
--- a/c4/demo2.c
+++ b/c4/demo2.c
@@ -100,9 +100,10 @@
         // results from consecutive read_barriers can differ. needs Ptr_Eq()
         int i = 0;
         while (!(stm_read_barrier((gcptr)r_prev->next) ==
-                 stm_read_barrier((gcptr)r_current) &&
+                 ((gcptr)r_current) &&
                  stm_read_barrier((gcptr)r_current->next) ==
-                 stm_read_barrier((gcptr)r_next))) {
+                 ((gcptr)r_next))) {
+            abort();
             asm volatile ("pause":::"memory");  /* smp_spinloop() */
             i++;
             assert(i < 1000);
diff --git a/c4/et.c b/c4/et.c
--- a/c4/et.c
+++ b/c4/et.c
@@ -640,15 +640,34 @@
       if (v >= LOCKED)            // locked
         {
           if (!during_commit)
-            assert(v != d->my_lock);    // we don't hold any lock
-
-          if (v != d->my_lock)
             {
-              /* not locked by me: spinloop until the other thread releases
-                 its lock */
+              assert(v != d->my_lock);    // we don't hold any lock
+              /* spinloop until the other thread releases its lock */
               SpinLoop(SPLP_LOCKED_VALIDATE);
               goto retry;
             }
+          else
+            {
+              if (v != d->my_lock)         // not locked by me: conflict
+                {
+                  /* A case that can occur: two threads A and B are both
+                     committing, thread A locked object a, thread B
+                     locked object b, and then thread A tries to
+                     validate the reads it did on object b and
+                     vice-versa.  In this case both threads cannot
+                     commit, but if they both enter the SpinLoop()
+                     above, then they will livelock.
+
+                     XXX This might lead both threads to cancel by
+                     reaching this point.  It might be possible to be
+                     more clever and let one of the threads commit
+                     anyway.
+                  */
+                  fprintf(stderr, "validation failed: "
+                          "%p is locked by another thread\n", R);
+                  return 0;
+                }
+            }
         }
     }
   return 1;
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to