In: Computer Science
The two variables a and b have initial values of 1 and 2, respectively. The following code is for a Linux system:
What possible errors are avoided by the use of the memory barriers?
Without using the memory barriers, on some processors it is possible that c receives the new value of b, while d receives the old value of a. For example, c could equal 4 (what we expect), yet d could equal 1 (not what we expect). Using the mb( ) insures a and b are written in the intended order, while the rmb( ) insures c and d are read in the intended order
Using the mb( ) insures a and b are written in the intended order, while the rmb( ) insures c and d are read in the intended order