windows - Does concurrent READ/WRITE access to memory by itself cause errors/violations? -


if have multiprocessor setup , 2 threads access same memory (let's same actual byte or word, not "the same area"), cause errors itself?

what if 2 threads not reading, writing , combining reading , writing (say, thread 1 tries read @ same time thread 2 trying write, or if both trying write @ same time). cause error/bsod/av, or problem behaviour undefined? (that 1 of threads wrong data, dependent on actual timings)

1) no, threads free read/write everywhere in program application memory. (ok, possible protect part of memory, program code memory protect it.)

2) cpu core has own cache , data first copied , modified in cache line after copied @ appropriate (unpredictable) time ram. there special cpu instruction (like lock) must executed other instruction (like cmpxchg) ensure atomic (interlocked) ram read, write or modify, instructions atomic default.

remember: atomic (interlocked) ram access can 1, 2, 4 or 8 (and 16 under 64bit cpu) bytes long. longer memory structures must ensure corresponding locking (sinhronisation) mechanism critical section avoid uncontroled memory access several threads.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -