changed on deeper level.
When we change non-volatile variable A, we read it to CPU cache, then apply changes and flush back to RAM (or not)
When we read volatile variable, we request actual value directly from RAM and don't use cached version. But how do we write to it (change) ? Consider there is volatile int A and a thread incrementing it, how will it do it? Will it perform three steps (reading to cache - changing - writing back immediatly) or just will change it in the RAM without reading it somewhere?
You should never worry about what the hardware is doing when you're handling volatile. As a programmer, you view it as software guarantees on variable read and write. You're using all the wrong terms for fetching an address. HDD is involved, RAM is involved, tier cache is involved, hardware buffers are involved. To properly deal with multithreading, you only need to worry about the guarantees the programming language exhibits. There are some best practices, but that's still all software.
Обсуждают сегодня