multithreading - Does Delphi have any equivalent to C's volatile variable? -
in c , c++ variable can marked volatile, means compiler not optimize because may modified external declaring object. there equivalent in delphi programming? if not keyword, maybe work around?
my thought use absolute, wasn't sure, , may introduce other side effects.
short answer: no.
however, not aware of situation in conservative approach of compiler change number of reads or writes if follow approach:
when reading cross-thread visible location, save value local before doing further manipulation; similarly, restrict writes single assignment.
the delphi compiler not perform common subexpression elimination (cse) on non-local location expressions when there calls non-inlined methods between expressions, compiler doesn't interprocedural optimization , not correct single-threaded code.
so, may want use interlockedexchange() reads , writes force this; additionally, cause full memory barrier, processor won't reorder reads , writes either.
Comments
Post a Comment