Is it safe for the thread to READ the variable set by the Delphi VCL event?
When a user clicks on the TCheckbox VCL, the main thread sets a boolean value in the Checked Checked field.
CheckboxState := CheckBox1.Checked;
At any time, the thread reads this variable.
if CheckBoxState then ...
It doesn’t matter if a thread “skips” a logical change, because the thread checks the variable in the loop, like other things. So he will see a change in state eventually ...
It is safe? Or do I need a special code? Is the surrounding read and write variable (in the stream and main stream, respectively) with the necessary and sufficient code calls?
As I said, it doesn’t matter if the thread gets the “wrong” value, but I keep thinking that there might be a low level problem if one thread tries to read the variable while the main thread is in the middle of writing or vice versa .
My question is like this: Cross-reading a variable whose value is not considered important .
(Also relevant to my previous question: Using EnterCriticalSection in a stream to update VCL label )
source share