Skip to main content

Chapter 5: Thread synchronization and classic problems

In this chapter

  • Why synchronization is needed: the risk of shared data
  • Classic problems
    • Race condition
    • Deadlock
    • Common deadlock-prevention strategies
  • Synchronization mechanisms
    • Interlocked: atomic operations on a single field
    • The lock keyword: the simplest lock
    • A more modern lock: System.Threading.Lock (.NET 9+)
    • The boundary between lock and async
    • SemaphoreSlim: limiting concurrency
    • Mutex: cross-process synchronization
  • Summary

This chapter is not available in the free preview. Purchase the book to read the complete edition now.

Buy this book