<div>Hello,</div><div> </div><div>> btw, how would you do that if it is in not guaranteed? especially on arm</div><div> </div><div>There are memory barriers in FPC: ReadBarrier, WriteBarrier etc.</div><div>I didn't investigate it but probably these barriers are for CPU only - gives guarantee that load/store operations are finished and thus you can rely on a particular partial order of operations between threads.</div><div>Does the barriers affect compiler optimizations (using registers for example)?</div><div>Seems no, so if you assign a value to a variable the variable can be cached in a register and despite the barrier other thread will not see the new value.</div><div>If it's correct, the barriers are useful only with direct memory access using pointer math for example.</div><div>Traditional synchronization methods (mutexes, locks etc) do issue necessary memory barriers automatically.</div><div> </div><div>A good example of volatile keyword implementation is in Java:</div><div>Access to a volatile variable issue corresponding memory barriers and affect compiler optimizations (reordering, register caching etc) so there is documented guarrantee that accesses to volatile variables are ordered. Such volatile variables are very useful.</div><div> </div><div>> Are there functions to do only an atomic reads and writes? (besides functions like interlockedincrement that do both, a read and write, together)</div><div> </div><div>Typically, read/write of aligned data with size native to platform is atomic. But if a compiler or runtime doesn't gurrantee that (as Java does) you have to use such things as CompareAndSwap (InterlockedCompareExchange in FPC).</div><div> </div><div>As an option, you can use ready solutions such as PasMP.<br /><br />---</div><div>Best regards, George</div>