Summary

In this chapter, we have learned how we can synchronize concurrent access to shared data without locking. We found out what a memory model and atomic operation are and how the .NET Framework allows programmers to use them in code. We have discussed the major problems related to lock-free programming and made sure that atomicity is necessary, but not enough to make the concurrent code work right. Also, we have implemented a lock-free stack and queue and illustrated the lock-free approach with concrete examples.

In the next chapter, we will combine approaches that we have learned so far and see how we can structure a concurrent program to lower the performance overhead and optimize it, depending on what exactly the program does.

Get Mastering C# Concurrency now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.