compiler-constructionprocessorinstruction-reordering

How compiler and processor optimization works to speed up code execution?


In Linux Kernel Development (3rd Edition), Kernel Synchronization Methods, Ordering and Barriers. There is an example:

enter image description here

And I'm confused about the statement in this book:

Again, without memory barriers, it would be possible for b to be set to pp before pp was set to p.

So, does the author mean if there is no read_barrier_depends(), b = *pp would be executed before pp = p? How could this be possible?


Solution

  • I was interested in your problem, so I searched a bit longer. I found the post of the read_barrier_depends functionality on the kernel list, with some explanation:

    https://lwn.net/Articles/5159/