I am currently reading the Joe Albahari Threading e-book in C # , and sometimes in my code example, it uses locks in places where I do not see any thread's security problem. Here , for example, it blocks writing and reading from the _status field, which refers to an immutable object.
I understand that if the ProgressStatus class was changed, you would need to block its reading and writing, because if one thread was previously missed between updating the PercentComplete and StatusMessage fields with another thread reading the status, the second thread may receive an invalid pair of values ββfor these fields. (100% complete / "Operation in progress ...")
But since ProgressStatus is unchanged, such an invalid status cannot be. If Joe removed both of these locks, what thread safety issue could arise?
source share