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.

48 CHAPTER 5. PARTITIONING AND SYNCHRONIZATION DESIGNP151P5P2423P4P3Figure 5.2: Dining Philosophers Problem, Textbook<strong>So</strong>lutionThisgeneraltechniqueofnumberingresourcesandacquiring them in numerical order is heavily used asa deadlock-prevention technique. However, it is easyto imagine a sequence of events that will result inonly one philosopher eating at a time even thoughall are hungry:1. P2 picks up fork 1, preventing P1 from takinga fork.2. P3 picks up fork 2.3. P4 picks up fork 3.4. P5 picks up fork 4.5. P5 picks up fork 5 and eats.6. P5 puts down forks 4 and 5.7. P4 picks up fork 4 and eats.PleasethinkaboutwaysofpartitioningtheDiningPhilosophers Problem before reading further.

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

Saved successfully!

Ooh no, something went wrong!