READ_ONCE, WRITE_ONCE, ACCESS_ONCE

READ_ONCE, WRITE_ONCE, ACCESS_ONCE

Data race:  数据竞争

READ_ONCE(), WRITE_ONCE() only affects the compiler, not the CPU.

Why kernel code should use READ_ONCE and WRITE_ONCE for shared memory accesses

https://github.com/google/ktsan/wiki/READ_ONCE-and-WRITE_ONCE

There are several reasons to use at least READ_ONCE and WRITE_ONCE for all concurrent non-read-only shared memory accesses:

  • It makes code easier to understand
  • It is required by relevant standards
  • It enables automatic data race detection
  • It is required for kernel memory model
  • It may improve performance

And there are no reasons to not use them (see Performance considerations if you are worried about performance).

Reference:
https://mirrors.edge.kernel.org/pub/linux/kernel/people/paulmck/perfbook/perfbook.html
http://ifeve.com/perfbook/
https://github.com/paulmckrcu/perfbook

你可能感兴趣的:(parallel,program,html5,html)