flat assembler
Message board for the users of flat assembler.
Index
> Windows > Where is the load barrier for the volatile statement? |
Author |
|
revolution 05 Jan 2015, 15:24
Volatile means that the value must be in memory, i.e not in a register. Volatile provides no guarantee that it is thread safe. If you need thread safe then use a mutex, a critical section or a lock.
|
|||
05 Jan 2015, 15:24 |
|
revolution 05 Jan 2015, 15:26
About the cache thing. The cache coherency protocol ensure that all other cores will see the new value.
|
|||
05 Jan 2015, 15:26 |
|
revolution 05 Jan 2015, 15:27
And memory barriers are more designed for transactions rather than thread safety.
|
|||
05 Jan 2015, 15:27 |
|
salilsurendran 05 Jan 2015, 15:27
Yes I understand that volatile is not thread safe or atomic. I am asking as to how does the above assembly code bypass the cache and ensure that the volatile variable is written to memory. Then why isn't the value of i not seen by other thread?
|
|||
05 Jan 2015, 15:27 |
|
salilsurendran 05 Jan 2015, 15:32
if the cache coherence policy will make the value of j to be seen by other threads will the value of i also be seen by other threads which is being incremented by this statement "inc dword ptr [r10+74h] ". Also what is the LOCK statement doing? What is it's role in making sure that the volatile write gets propogated to memory?
|
|||
05 Jan 2015, 15:32 |
|
revolution 05 Jan 2015, 15:50
Volatile just means to always read and write a new value to/from memory. That is, don't keep it in a register. Originally it was used for I/O type memory that needs to see all changes (like a comms data port for example).
|
|||
05 Jan 2015, 15:50 |
|
revolution 05 Jan 2015, 15:59
I reread your Qs and perhaps your confusion is because you are conflating caches with memory and idempotentcy. Volatile tells the compiler that the memory is not idempotent. The involvement of caches in no way affects the results of the program unless the caches have been configured incorrectly by the BIOS/OS on inappropriate memory (unlikely).
|
|||
05 Jan 2015, 15:59 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.