Java – Delphi concurrent memory model?

Is there anything like Java Memory Model in Delphi? To prevent misunderstanding: I mean nothing like "big / big / small", but something related to the visibility of changes made by other threads

Solution

I would say that the Delphi memory model matches the C memory model That is, the compiler is unaware of multiple processes or threads and does not provide any special support for these situations See "what is the C + + memory model for concurrency?"

Delphi 32-bit compiler performs optimization, such as invariant code movement, and issues instruction sequences to avoid stopping double pipes However, Delphi compiler does not include instruction scheduler or peephole optimizer, so the chance of instruction reordering is very small Delphi optimization occurs on AST / IR before the command is issued

Local variables can be registered, but any source code reference to a variable that requires a memory address (such as passing a local variable to var param or using the address of a local variable) will force the compiler to submit the registered value to the memory location before the address is used, or may force the compiler to abandon the registration of variables completely

Delphi 32 - bit compiler is quite conservative in optimization The biggest performance improvement in optimization comes from registered variables and intermediate results, as well as various loop sensing techniques

Operations on global symbols or symbols that reside in global memory, such as object fields, are not registered There is no 'volatile' modifier

The compiler code pattern depends on x86 architecture rules. The registered size of aligned addresses is atomic when written to global memory Writes of large data, byte data, or misaligned addresses may span cache lines and require two separate writes within a single write instruction Delphi compiler (mainly) ignores this point

In any case, if you are writing Delphi code to access shared memory from different threads, it is always your responsibility to decide what thread synchronization measures are suitable for your situation and implement them

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>