John wrote:
> The example below works without errors (when Button1 is clicked that > is). But if you don't wrap shared variable (SupposedToBeThreadSafe) in > ProtectWrite and ProtectRead functions (as in commented lines) you > should get errors above.
Assigning a string to another string is thread-safe. Concatenating a string to another string is not. Concatenation requires multiple steps (reading string lengths, allocating memory, copying string characters), and the strings being concatenated could be modified by another thread while the concatenation is still in progress. That is why you get crashes when using un-protected access.
-- Remy Lebeau (TeamB)