Postby ESP_Sprite » Thu Mar 17, 2022 2:21 am
There's a long explanation that I could put here, but the 'plastered over' explanation is: no, it is not needed, and could actually stop the compiler from doing some optimizations. Volatile would be needed it you ran the code in a tight loop (e.g. 'while (variable) {}') as the compiler sees no way the variable could ever change and as such optimizes away the while loop. In your case, the xSemaphoreTake() function call makes the compiler assume that any variable could have changed (because, who knows, xSemaphoreTake could be a function that touches someVariable itself, for all the compiler knows), and someVariable will be read correctly.
(The details I plastered over are related to the memory model the ESP32 hardware uses; while it has a very simple cache that effectively is sequentially consistent, the Xtensa does have a single store buffer it can use, making the memory model more akin to TSO. This has technical implications if you want to go deep down the rabbit hole, but for your average embedded programmer, the effects of this are not really important.)