Info

This measure protects against the second erroneous reordering shown above.

All barrier commands discussed so far are made available by including <system.h>. You might have gotten the impression that memory barriers are notoriously complicated to use, and your perception serves you well, indeed — getting memory and optimization barriers right can be a very tricky business. It should therefore be noted that memory barriers are not particularly favored by some kernel maintainers, and code using them will have a hard time finding its way into mainline. So it's always worth a try to see if things cannot be done differently without barriers. This is possible because locking instructions will on many architectures also act as memory barriers. However, this needs to be checked for the specific cases that require memory barriers, and general advice is hard to give.

Continue reading here: Reader Writer Locks

Was this article helpful?

0 0