O'Reilly logo

Professional Parallel Programming with C#: Master Parallel Extensions With .NET 4 by Gastón C. Hillar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5. Coordination Data Structures

WHAT'S IN THIS CHAPTER?

  • Understanding lightweight coordination data structures

  • Working with lightweight synchronization primitives

  • Choosing the most appropriate synchronization primitive according to your needs

  • Synchronizing concurrent tasks with barriers

  • Working with timeouts and cancellation tokens combined with the synchronization primitives

  • Working with mutual-exclusion locks and critical sections

  • Refactoring code to avoid locks

  • Working with spin-based waiting

  • Understanding spinning and yielding

  • Working with lightweight manual reset events

  • Limiting concurrency to access a resource with a semaphore

  • Understanding and preventing synchronization-related bugs

  • Working with atomic operations

This chapter is about synchronizing the work performed by diverse concurrent tasks. The chapter covers some classic synchronization primitives and the new lightweight coordination data structures introduced by .NET Framework 4. It is important to learn the different alternatives, so that you can choose the most appropriate one for each concurrency scenario that requires communication and/or synchronization between multiple tasks. This way, you are going to be able to implement more complex algorithms and to solve potential bugs when the designs don't consider the problems associated with heavyweight synchronization mechanisms.

USING CARS AND LANES TO UNDERSTAND THE CONCURRENCY NIGHTMARES

Figure 5-1 shows one car in a single lane. There are three black flags and two gray ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required