As shown in the figure below, why does the api read this variable with critical protection?
Suppose two tasks have write operations to shared variables. For example:
var = 1;
var = 2;
In the OS source code, you can see that a critical section must be added to the shared variable write operation. There is no read-modify-write, and it should not cause a race condition. Why do you need to add a critical section?
If the compiler has done level optimization, there may be a write cache for variable writes. In this case, should the DSB data synchronization barrier be increased after the variable is written in the critical section? I don’t know when to use DSB, ISB, etc. instructions
Thank you very much.
OK,Thank you for your wonderful and authoritative answer, which solved my confusion, thank you again!