On 22/10/12 01:34, Emanuel Rumpf wrote:
Hi
With some threads running on different CPU,
accessing a shared pointer (in RAM) atomically (with gcc atomic methods)
my current understanding is:
- each cpu has its own cache line
- which is updated on every atomic read/write operation
1. is that applicable ?
2. is there a faster or more convenient method, such as
storing the pointer in fast register shared among different cpu ?
Depends on how you design your data structures and on the specific platform.
On x86 reads and writes of pointers are atomic so you won't ever end up
with the corrupt pointer, but you may end up with a stale one. This may
be, or may not be a problem, depending on your use and design, and there
are ways of designing things around it. If applicable to your use case.
If your data structures and their use require locking, which you would
like to avoid, there is a concept called Read-Copy-Update which is for
example heavily used in the kernel and is also available as an userspace
library (
http://lttng.org/urcu).
Tvrtko