I am confused about whether bit-banding is atomic or not. There seems to be some contradictory information on the forums, with some posts saying it is atomic, others saying it is not.
For example this thread indicates bit-banding is atomic:
But this thread indicates that bit-banding performs a read-modify-write:
I need to implement a "bit array." Normally that is very simple, but in this case, the bit array can be read and written from main code and interrupts, so is subject to corruption: if code that writes a bit is interrupted after the read but before the write by other code that writes a different bit in the same word, the change to that different bit will be lost when the earlier code resumes.
According to posts elsewhere on e2e, bit-banding is supposedly atomic, in which case bit-banding could be used to solve that corruption issue. But according to posts in this thread, bit-banding performs a read-modify-write, which indicates that it may be corruptible -- unless the entire read-modify-write operation is uninterruptible or there is some other CPU mechanism by which the operation is cancelled and restarted if interrupted (in the same way that a time-consuming DIV operation can be cancelled and restarted in some CPU platforms, to reduce interrupt latency).
So, it is very important that I understand whether bit-banding is atomic or not. If multiple threads or interrupt handlers access different bits in the same word by means of bit-banding, can such corruption occur?
Of course, I am interested in other suggestions to solve this issue.
Thanks