3
votes

Is it safe to assume that assigning and accessing 32 bit integers on an ARM Cortex-A9 MPCore implementations are atomic operations and that the assigned value is synchronized with all cores? Will the C compiler guarantee that

uint32_t *p;
*p = 4711;

and

uint32_t *p;
return *p;

are translated to atomic operations in assembler?

2
You could always disassemble the object files and check for yourself. - Some programmer dude
@JoachimPileborg, don't ever do that. The results might change from one build configuration to another. - sh1

2 Answers

4
votes

"Atomic" and "synchronized with all cores" are different requirements. All ARM cores in the market implement 32 bit operations to memory atomically (which is to say you can never see "part" of the word written without the rest). Not all of them are cache-coherent between cores, and the details (especially with the more exotic configurations like big.LITTLE) are complicated.

Use your OS synchronization primitives. That complexity is what they are designed to abstract.

2
votes

No that is the reason for the strex/ldrex. Within the core a normal str and ldr are fine, but to insure access for the other cores you have to use strex/ldrex (and have a memory system that supports them).