This patch fixes a lost wake-up bug in the futex-based serial lock implementation. The previous code lacked some pieces of synchronization (a seq_cst barrier and resetting a flag that is checked by the respective futex_wait()), which led to those lost wake-ups when waking and waiting were racing against each other. Tested on ppc64 with microbenchmarks/STAMP and gl_wt.
OK for trunk?
commit a04fadca7c74f35d6d1d4f12d745c0ab44cc315a Author: Torvald Riegel <trie...@redhat.com> Date: Tue Jan 24 15:05:42 2012 +0100 libitm: Fix wake-up of readers in futex-based serial lock. libitm/ * config/linux/rwlock.cc (GTM::gtm_rwlock::write_unlock): Fix reader wake-up. diff --git a/libitm/config/linux/rwlock.cc b/libitm/config/linux/rwlock.cc index 24e7042..ad1b042 100644 --- a/libitm/config/linux/rwlock.cc +++ b/libitm/config/linux/rwlock.cc @@ -231,10 +231,13 @@ gtm_rwlock::write_unlock () // last writer (this can happen because write_lock_generic() // exchanges 0 or 1 to 2 and thus might go to contended mode even if // no other thread holds the write lock currently). Therefore, we - // have to wake up readers here as well. - futex_wake(&readers, INT_MAX); + // have to wake up readers here as well. Execute a barrier after + // the previous relaxed reset of writers (Dekker-style), and fall + // through to the normal reader wake-up code. + atomic_thread_fence (memory_order_seq_cst); } - return; + else + return; } // No waiting writers, so wake up all waiting readers. // Because the fetch_and_sub is a full barrier already, we don't need