Re: [Maria-developers] Missing memory barrier in parallel replication error handler in wait_for_prior_commit()?
![](https://secure.gravatar.com/avatar/99fde0c1dfd216326aae0aff30d493f1.jpg?s=120&d=mm&r=g)
sujatha
I have a doubt. A simple fix as per the earlier mail discussion would be to swap the
order of assignments as shown below.
wakeup_error= true waitee= NULL
Why cannot we use the simpler approach. Please provide your inputs.
This is because of the need for memory barriers, to prevent compiler and/or modern high-performance CPUs from re-ordering the memory accesses. There is nothing in C that requires the compiler to make the two assignments in the same order as in the source code. And even if it does, the CPU is free to perform the writes and/or the corresponding loads in the opposite order (the x86 architecture doesn't do that, but other architectures do). There are many resources on the net on the need for memory barriers, for example this from one of your collegues: https://mariadb.org/wp-content/uploads/2017/11/2017-11-Memory-barriers.pdf But it will be difficult to make a test case, I think. Because after correcting the order of the stores there is nowhere to put a debug-sleep, and there also is no easy way to force the CPU to take the incorrect memory order. - Kristian.
participants (1)
-
Kristian Nielsen