Cover Page by Eric Lippert, Mark Michaelis

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

19. Thread Synchronization

In the preceding chapter, we discussed the details of multithreaded programming using the Task Parallel Library (TPL) and Parallel LINQ (PLINQ). One topic we specifically avoided, however, was thread synchronization, which prevents race conditions while avoiding deadlocks. Thread synchronization is the topic of this chapter.

Image

We begin with a multithreaded example with no thread synchronization around shared data—resulting in a race condition in which data integrity is lost. This serves as the introduction for why we need thread synchronization followed by myriad mechanisms and best practices for doing it.

Prior editions ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required