10.07.2015 Views

Is Parallel Programming Hard, And, If So, What Can You Do About It?

Is Parallel Programming Hard, And, If So, What Can You Do About It?

Is Parallel Programming Hard, And, If So, What Can You Do About It?

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 6LockingTheroleofvillaininmuchofthepastfewdecades’concurrency research literature is played by locking,which stands accused of promoting deadlocks,convoying, starvation, unfairness, data races, andall manner of other concurrency sins. Interestinglyenough, theroleofworkhorseinshared-memoryparallelsoftware is played by, you guessed it, locking.There are a number of reasons behind this dichotomy:1. Many of locking’s sins have pragmatic designsolutions that work well in most cases, for example:(a) Lock hierarchies to avoid deadlock.(b) Deadlock-detection tools.(c) Locking-friendly data structures, such asarrays, hash tables, and radix trees.2. <strong>So</strong>me of locking’s sins are problems only athigh levels of contention, levels that are usuallyreached only by poorly designed programs.3. <strong>So</strong>me of locking’s sins are avoided by usingother synchronization mechanisms in concertwith locking, such as reference counters, statisticalcounters, simple non-blocking data structures,and RCU.4. Until quite recently, almost all large sharedmemoryparallelprogramsweredevelopedinsecret,so that it was difficult for most researchersto learn of these pragmatic solutions.5. All good stories need a villain, and lockinghas a long and honorable history serving as aresearch-paper whipping boy.This chapter will give an overview of a number ofways to avoid locking’s more serious sins.6.1 Staying AliveGiven that locking stands accused of deadlockand starvation, one important concern for sharedmemoryparallel developers is simply staying alive.The following sections therefore cover deadlock, livelock,starvation, unfairness, and inefficiency.6.1.1 Deadlock6.1.2 Livelock6.1.3 Starvation6.1.4 Unfairness6.1.5 Inefficiency6.2 Types of Locks6.2.1 Exclusive Locks6.2.2 Reader-Writer Locks6.2.3 Beyond Reader-Writer LocksSequence locks. VAXCluster six-state locking.6.2.4 While WaitingSpinlocks, sleeplocks, spin-sleeplocks (maybe), conditionallocking.6.2.5 Sleeping Safely6.3 Lock-Based ExistenceGuaranteesA key challenge in parallel programming is to provideexistence guarantees [GKAS99], so that attemptsto delete an object that others are concurrentlyattempting to access are correctly resolved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!