Cache Line Ping Pong
Cache Line Ping Pong
s keep trying and retrying to perform operations on the same cache line. To service these operations, the cache linebounces back and forth ( ping-pongs) between the contending threads. locked algorithm may outperform the non-blocking e!uivalent if lock contention is sufficiently distributed."#perimentation is necessary to find out whether the non-blocking or locked algorithm is better. rough guide is that a fast spin lock protecting a critical section with no atomic operations may outperform an alternative non-blocking design that re!uires three or more highly contended atomic operations. MEMORY RECLAMATION PROBLEM: $emory reclamation is the dirty laundry of many non-blocking algorithms. %or languages such as &'&(( that re!uire the programmer to e#plicitly free memory, it turns out to be surprisingly difficult to call free on a node used in a non-blocking algorithm. The problem occurs for algorithms that remove nodes from linked structures, and do so by performing compare-e#change operations on fields in the nodes. %or e#ample, non-blocking algorithms for !ueues do this. The reason is that when a thread removes a node from a data structure, without using a lock to e#clude other threads, it never knows if another thread still looking at the node. The solution is to use a garbage collector or mini-collector like ha)ard pointers. lternatively you may associate a free list of nodes with the data structure and not free any nodes until the data structure itself is freed.
RECOMMENDATIONS: Non-blocking algorithms big advantage is avoiding lock pathologies. Their primary disadvantage is that they are much more complicated than their locked counterparts. Non-blocking algorithms are difficult to verify. None#perts should consider the following advice: tomic increment, decrement, and fetch-and-add are generally safe to use in an intuitive fashion. The fetch-and-op idiom is generally safe to use with operations that are commutative and associative. The creation of non-blocking algorithms for linked data structures should be left to e#perts. *se algorithms from the peer-reviewed literature. +e sure to understand any memory reclamation issues. void having more runnable software threads than hardware threads, and design programs to avoid lock contention.