← Back to team overview

maria-developers team mailing list archive

Re: Missing memory barrier in parallel replication error handler in wait_for_prior_commit()?


sujatha <sujatha.sivakumar@xxxxxxxxxxx> writes:

> 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:


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

 - Kristian.