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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

136 CHAPTER 12. ADVANCED SYNCHRONIZATIONCPUMemoryCPUCoreMemoryAccessQueueCPUCacheMemoryCacheCoherencyMechanismCPUCoreMemoryAccessQueueCPUCacheDeviceFigure 12.17: Memory ArchitectureCPU 1CPU 2Cache ACache BCache CCache DMemorySystemFigure 12.18: Split Cachesparticular piece of code, then memory barriers areunnecessary in that piece of code.Notethatthesearetheminimum guarantees. Differentarchitectures may give more substantial guarantees,as discussed in Appendix C, but they maynot be relied upon outside of code specifically designedto run only on the corresponding architecture.However, primitives that implement atomic operations,such as locking primitives and atomic datastructuremanipulation and traversal primitives, willnormally include any needed memory barriers intheir definitions. However, there are some exceptions,such as atomic_inc() in the Linux kernel, sobe sure to review the documentation, and, if possible,the actual implementations, for your softwareenvironment.One final word of advice: use of raw memorybarrierprimitives should be a last resort. <strong>It</strong> is almostalways better to use an existing primitive thattakes care of memory barriers.12.3 Non-Blocking Synchronization12.3.1 Simple NBS12.3.2 Hazard Pointers@@@ combination of hazard pointers and RCU toeliminate memory barriers?12.3.3 Atomic Data StructuresQueuesandstacks—avoidingfull-racenon-blockingproperties often yields great simplifications.12.3.4 “Macho” NBSCite Herlihy and his crowd.Describe constraints (X-freedom, linearizability,...) and show examples breaking them.

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

Saved successfully!

Ooh no, something went wrong!