Re: Lock variables between two threads

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



"Ben Voigt [C++ MVP]" wrote:
Yes, but can the CPU exchange single bytes with main memory (or
L2/L3 cache shared between cores), or always an entire word (or
more)? I guess the cache coherency protocol guarantees
atomicity of the read/modify/write to the cache line even with
an instruction without LOCK prefix.

Actually, you cannot use LOCK prefix with MOVx instructions. There
is limited set of instructions that can utilize LOCK prefix. Also,
according to Intel SW developer manual, reading and writing a byte
from/to memory is atomic operaton:

<quote>
7.1.1. Guaranteed Atomic Operations
The Intel386T, Intel486T, Pentium®, and P6 family processors
guarantee that the following basic memory operations will always
be carried out atomically:
.. Reading or writing a byte.
.. Reading or writing a word aligned on a 16-bit boundary.
.. Reading or writing a doubleword aligned on a 32-bit boundary.
</quote>

Alex


.



Relevant Pages

  • Re: Memory copy
    ... I suspect that the particular CPU you are testing this on has an n-way ... the locations you are reading from and then writing ... With such cache contention, that level of cache ...
    (comp.lang.c)
  • Re: page table lock patch V15 [0/7]: overview
    ... all the stuff we put in to simulate 64 bit atomicity for i386 PAE mode if ... reading or writing a word aligned on a 16-bit boundary ... that the following additional memory operations will always be carried out ...
    (Linux-Kernel)
  • Re: Lock variables between two threads
    ... I guess the cache coherency protocol guarantees atomicity of the read/modify/write to the cache line even with an instruction without LOCK prefix. ... I guess the moral of the story is that avoiding false sharing is at least as important to performance as avoiding unnecessary LOCK prefixes (although maybe only with a few cores, whereas the LOCK prefix is worse with many-core). ...
    (microsoft.public.vc.language)
  • Re: mm/filemap.c: atomic file read(2)/write(2) ?
    ... There are file descriptors that have atomicity guarantees (pipes(, ... - take a page fault - sleep ... from the old page cache contents and not re-read. ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: Memory Consistency Errors
    ... While reading the tutorial http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html, ... It is said that memory consistency errors can occur even when atomicity of reading/writing access is guaranteed with volatile. ... "Atomic actions cannot be interleaved, so they can be used without fear of thread interference. ...
    (comp.lang.java.programmer)