mschnell wrote: ↑
Sun Sep 19, 2021 12:39 pm
You can't know this unless you see the code the compiler generates.
I looked at what the compiler generates.
It could call a function that returns a 32 bit word or it could call a function that takes a pointer to a 32 bit word. in the (unlikely) second case the ROM function could write a single byte (e.g. the exponent) independently of the other three.
No idea what you're trying to say...
Moreover the line
x += 1;
is not atmic...
I wouldn't expect that to be atomic, because it's a load-modify-store construct. I think we have a different understanding of what atomic means. An atomic operation is an operation that will always be executed without any other process being able to read or change state that is read or changed during the operation. At the machine level I define 'operation' as meaning a machine instruction.
On CM0 loading or storing a float generates a single instruction thus is atomic. Loading or storing a double requires two instructions therefore is not atomic. Same for int and long long int.
Higher level languages like C++ support generalized atomic objects, but my interpretation applies to the OP's case where one thread simply stores a float or int variable while another thread tries to read it.
Note that even in C++, no special action is taken for atomic 32 bit value loads and stores.
Code: Select all
i = 123;
int j = i;
will compile to simple single LDR and STR instruction enclosed in memory barriers. No need for anything else since those are naturally atomic.