Is it atomic to access(load/store) 32 bit integer when using ARM Thumb instruction set?
Using ARM cortex wit开发者_开发知识库h thumb instruction set and Keil realview compiler, is it safe to access to 32 bit integer? Since the thumb register set is 16 bits, does this mean, fetching a 32 bit int needs 2 machine instructions? If so, accessing 32 bit will not be atomic. If my worry is true, does it mean that int assignment should be protected by a critical region?
Thumb uses the same 32-bit registers as ARM, so there's no issue there. What's halved is the instruction size (and even that is not strictly true for Thumb-2).
Do not worry, you don't need to change your code if you're compiling to Thumb.
The instruction size is 16-Bit in thumb mode, not the register size.
This means that a constant assignment - as in i=1;
- can be seen as atomic. Although more than one instruction is generated, only one will modify the memory location of i
even if i
is int32_t
.
But you need a critical section once you to things like i=i+1
. That is of course not atomic.
精彩评论