Setting a string is an atomic operation, that is, you either get a new string or an old string, you never get garbage.
If you do any work, for example.
obj.SampleProperty = "Dear " + firstName + " " + lastName;
then string concatenation occurs before the call is set, so sampleField will always be either a new line or an old one.
If, however, your string concatenation code is self-relational, for example.
obj.SampleProperty += obj.SampleProperty + "a";
and where in another thread is
obj.SampleProperty = "Initial String Value";
Then you will need a lock.
Suppose you are working with int. If you assign int, and any value you get from int is valid, then you don't need to block it.
However, if int is counting the number of widgets processed by two or more threads so that the count is accurate, you need to block int. This is the same situation for strings.
I have a feeling that I didnโt explain it very well, I hope this helps.
thank
Bw
Binary Worrier Jan 12 '09 at 9:31 2009-01-12 09:31
source share