What are Memory Barriers ?

Many processors and compilers reorder instructions to achieve optimal execution speeds. The reordering is done such that the new instruction stream is semantically equivalent to the original one. For example, writing to memory mapped registers on an I/O device, instruction reordering can generate unexpected behaviors
 
To prevent such cases the memory barriers comes into picture, these prevents the processor from reordering instructions, we can insert a barrier in our code to prevent reordering instructions. The wmb() function inserts a road block that prevents writes from moving through it, rmb() provides a read barricade that disallows reads from crossing it, and mb() results in a read-write barrier.
Previous Post Next Post

Contact Form