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.

F.10. CHAPTER 13: EASE OF USE 309Quick Quiz 12.10:<strong>What</strong> effect does the following sequence have on theorder of stores to variables “a” and “b”?a = 1;b = 1;Answer:Absolutely none. This barrier would ensure thatthe assignments to “a” and “b” happened beforeany subsequent assignments, but it does nothing toenforce any order of assignments to “a” and “b”themselves.Quick Quiz 12.11:<strong>What</strong> sequence of LOCK-UNLOCK operationswould act as a full memory barrier?Answer:A series of two back-to-back LOCK-UNLOCKoperations, or, somewhat less conventionally,an UNLOCK operations followed by a LOCKoperation.Quick Quiz 12.12:<strong>What</strong> (if any) CPUs have memory-barrier instructionsfrom which these semi-permiable lockingprimitives might be constructed?Answer:<strong>It</strong>anium is one example. The identification of anyothers is left as an exercise for the reader.Quick Quiz 12.13:Given that operations grouped in curly bracesare executed concurrently, which of the rows ofTable 12.2 are legitimate reorderings of the assignmentsto variables “A” through “F” and theLOCK/UNLOCK operations? (The order in thecode is A, B, LOCK, C, D, UNLOCK, E, F.) Whyor why not?Answer:1. Legitimate, executed in order.2. Legitimate, the lock acquisition was executedconcurrently with the last assignment precedingthe critical section.3. Illegitimate, the assignment to “F” must followthe LOCK operation.4. Illegitimate, the LOCK must complete beforeany operation in the critical section. However,the UNLOCK may legitimately be executedconcurrently with subsequent operations.5. Legitimate, the assignment to “A” precedes theUNLOCK, as required, and all other operationsare in order.6. Illegitimate, the assignment to “C” must followthe LOCK.7. Illegitimate, the assignment to “D” must precedethe UNLOCK.8. Legitimate, all assignments are ordered with respectto the LOCK and UNLOCK operations.9. Illegitimate, the assignment to “A” must precedethe UNLOCK.Quick Quiz 12.14:<strong>What</strong> are the constraints for Table 12.2?Answer:They are as follows:1. LOCK M must precede B, C, and D.2. UNLOCK M must follow A, B, and C.3. LOCK Q must precede F, G, and H.4. UNLOCK Q must follow E, F, and G.F.10 Chapter 13: Ease of UseQuick Quiz 13.1:<strong>Can</strong> a similar algorithm be used when deletingelements?Answer:Yes. However, since each thread must hold the locksof three consecutive elements to delete the middleone, if there are N threads, there must be 2N + 1elements (rather than just N + 1 in order to avoiddeadlock.Quick Quiz 13.2:

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

Saved successfully!

Ooh no, something went wrong!