how to make atomic instruction
in multithreading if many threads change the value of a global variable,(instruction is in execute procedure) like this:
for sure this one must be an atomic instruction, so what should I add to my code to make this instruction atomic?
In modern Delphi you should use the intrinsic function AtomicIncrement. There are a whole family of such functions in the RTL that provide atomic operations. For instance atomic exchange, atomic compare and swap and so on.
For your code you would write:
The benefit of using intrinsic functions is that the compiler inlines the asm instructions at the call site.
In older versions of Delphi you should use InterlockedIncrement. Again, there are a family of similarly named functions.