There is a class that has a public int counter field that is accessed by multiple threads. This int is only incremented or decremented. To increment this field, three thread-safe approaches are mentioned below:
A) lock(this.locker) this.counter++;
B) Interlocked.Increment(ref this.counter);
C) Change the access modifier of counter to public volatile
Which statement is incorrect with regards to these approaches?
Correct Answer: B is the best approach as it effectively does the read, increment, and write in 'one hit' which can't be interrupted.
Explanation:
Note: This Question is unanswered, help us to find answer for this one
More C# MCQ Questions