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.

310 APPENDIX F. ANSWERS TO QUICK QUIZZESYetch!!! <strong>What</strong> ever possessed someone to come upwith an algorithm that deserves to be shaved asmuch as this one does???Answer:That would be Paul.He was considering the Dining Philosopher’sProblem, which involves a rather unsanitaryspaghetti dinner attended by five philosphers. Giventhat there are five plates and but five forks on thetable, and given that each philosopher requires twoforks at a time to eat, one is supposed to come upwith a fork-allocation algorithm that avoids deadlock.Paul’s response was “Sheesh!!! Just get fivemore forks!!!”.This in itself was OK, but Paul then applied thissame solution to circular linked lists.This would not have been so bad either, but hehad to go and tell someone about it!!!Quick Quiz 13.3:Give an exception to this rule.Answer:One exception would be a difficult and complexalgorithm that was the only one known to workin a given situation. Another exception wouldbe a difficult and complex algorithm that wasnonetheless the simplest of the set known to workin a given situation. However, even in these cases,it may be very worthwhile to spend a little timetrying to come up with a simpler algorithm! Afterall, if you managed to invent the first algorithm todo some task, it shouldn’t be that hard to go on toinvent a simpler one.F.11 Chapter 15: ConflictingVisions of the FutureQuick Quiz 15.1:<strong>What</strong> about non-persistent primitives representedby data structures in mmap() regions of memory?<strong>What</strong> happens when their is an exec() within acritical section of such a primitive?Answer:<strong>If</strong> the exec()ed program maps those same regionsof memory, then this program could in principlesimply release the lock. The question as to whetherthis approach is sound from a software-engineeringviewpoint is left as an exercise for the reader.F.12 Chapter A: ImportantQuestionsQuick Quiz A.1:<strong>What</strong> SMP coding errors can you see in theseexamples? See time.c for full code.Answer:1. Missing barrier() or volatile on tight loops.2. Missing Memory barriers on update side.3. Lack of synchronization between producer andconsumer.Quick Quiz A.2:How could there be such a large gap betweensuccessive consumer reads? See timelocked.c forfull code.Answer:1. Theconsumermightbepreemptedforlongtimeperiods.2. A long-running interrupt might delay the consumer.3. The producer might also be running on a fasterCPU than is the consumer (for example, one ofthe CPUs might have had to decrease its clockfrequency due to heat-dissipation or powerconsumptionconstraints).F.13 Chapter B: SynchronizationPrimitivesQuick Quiz B.1:Give an example of a parallel program that couldbe written without synchronization primitives.Answer:There are many examples. One of the simplest

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

Saved successfully!

Ooh no, something went wrong!