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.

132 CHAPTER 12. ADVANCED SYNCHRONIZATIONCPU 1000 111 A=1000 111000 111 B=2000 111000 111wwwwwwwwwwwwwwwwAt this point the readbarrier causes all effectsprior to the storage of Bto be perceptible to CPU 20000 1111A−>00000 1111B−>90000 11110000 11110000 1111B−>20000 11110000 11110000 1111A−>10000 1111rrrrrrrrrrrrrrrrrCPU 2Figure 12.11: Read Barrier SuppliedCPU 1000 111 A=1000 111000 111 B=2000 111000 111wwwwwwwwwwwwwwwwAt this point the readbarrier causes all effectsprior to the storage of Bto be perceptible to CPU 20000 1111A−>00000 1111B−>90000 11110000 11110000 1111B−>20000 11110000 1111A−>00000 11110000 1111A−>10000 11110000 1111rrrrrrrrrrrrrrrrrFigure 12.12: Read Barrier Supplied, <strong>Do</strong>uble LoadCPU 21st2nd12.2.11 Locking ConstraintsAs noted earlier, locking primitives contain implicitmemory barriers. These implicit memory barriersprovide the following guarantees:1. LOCK operation guarantee:• Memory operations issued after the LOCKwill be completed after the LOCK operationhas completed.• Memory operations issued before theLOCK may be completed after the LOCKoperation has completed.2. UNLOCK operation guarantee:• Memory operations issued before the UN-LOCK will be completed before the UN-LOCK operation has completed.• Memory operations issued after the UN-LOCK may be completed before the UN-LOCK operation has completed.3. LOCK vs LOCK guarantee:• All LOCK operations issued before anotherLOCK operation will be completedbefore that LOCK operation.4. LOCK vs UNLOCK guarantee:• AllLOCKoperationsissuedbeforeanUN-LOCK operation will be completed beforethe UNLOCK operation.• All UNLOCK operations issued before aLOCK operation will be completed beforethe LOCK operation.5. Failed conditional LOCK guarantee:• Certain variants of the LOCK operationmay fail, either due to being unable toget the lock immediately, or due to receivinganunblockedsignalorexceptionwhilstasleep waiting for the lock to become available.Failed locks do not imply any sort ofbarrier.

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

Saved successfully!

Ooh no, something went wrong!