Bug #62692 rw_lock_free might cause assertion failure by race condition
Submitted: 12 Oct 2011 5:57 Modified: 16 Sep 2014 23:18
Reporter: Yasufumi Kinoshita Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: InnoDB Plugin storage engine Severity:S3 (Non-critical)
Version:all OS:Any
Assigned to: Marko Mäkelä CPU Architecture:Any

[12 Oct 2011 5:57] Yasufumi Kinoshita
Description:
The assertion code
"ut_a(lock->lock_word == X_LOCK_DECR);"
at rw_lock_free()/rw_lock_free_func()
might be race condition, thought it might be very rare or architecture dependent.

How to repeat:
Sorry, it should be very very difficult to reproduce...

Suggested fix:
"ut_a(rw_lock_lock_word_decr(lock, X_LOCK_DECR));"
is not affected by race condition.
[12 Oct 2011 6:45] Valeriy Kravchuk
Thank you for the problem report.
[22 Feb 2012 3:04] Yasufumi Kinoshita
I was wrong

"ut_a(rw_lock_lock_word_decr(lock, X_LOCK_DECR) && lock->lock_word == 0);"

is equivalent to x-lock
[16 Sep 2014 23:18] Daniel Price
Fixed as of the upcoming 5.6.22 and 5.7.6 releases, and here's the changelog entry:

For explicit cache coherency, a write barrier was added to the head of
"os_thread_create_func()", and a read barrier was added to before the
assertion code in "rw_lock_free_func()". 

This bug fix also addresses Bug #72809.

Thank you for the bug report.
[10 Dec 2014 13:04] Laurynas Biveinis
$ bzr log -r 6163
------------------------------------------------------------
revno: 6163
committer: Yasufumi Kinoshita <yasufumi.kinoshita@oracle.com>
branch nick: mysql-5.6
timestamp: Tue 2014-09-16 16:46:24 +0900
message:
  Some memory barrier were added for non-intel architecture (POWER, ARM, etc..)
  
  Bug#18870970 : INNODB LINUX NATIVE AIO SETUP MISSING BARRIER AFTER SETUP (Bug#72809)
  For explicit cache coherency with the parent thread, write barrier is added to the head of os_thread_create_func()
  
  Bug#13364876 : RW_LOCK_FREE MIGHT CAUSE ASSERTION FAILURE BY RACE CONDITION (Bug#62692)
  For explicit cache coherency with the other thread, read barrier is added to before the assertion codes at rw_lock_free_func()
  
  Approved by Vasil in rb#6255