CPSC 3220 - DAY 11 OCTOBER 5, 2017 ================================================================================ Chapter 6 --------- Multi-object Programs Synchronization Performance -A program with lots of concurrent threads can still have poor performance on a multiprocessor -Overhead of creating threads, if not needed -Lock contention: only one thread at a time can hold a given lock. -Shared data protected by a lock may ping back and forth between cores -False sharing: communication between cores even for data is not shared. Multiprocessor Cache Coherence Scenario: -Thread A modifies data inside a critical section and releases a lock. -Thread B acquires lock and reads data. Easy if all accesses go to main memory. -Ex. Thread A changes main mem, thread B reads it. Write Back Cache Coherence Cache coherence = system behaves as if there is one copy of the data -If the data is only being read, any number of caches can have a copy. -If data is being modified, at most one cached copy On write: (get ownership) -Invalidate all cached copies, before doing write -Modified data stays in cache ("write back") On read: -Fetch value from owner or from memory. Directory Based Cache coherence How do we know which cores have a location cached? -Hardware keeps track of all cached copies -On a read miss, if held exclusive, fetch latest copy and invalidate that copy. -On a write miss, invalidate all copies Read-modify-write instructions -Fetch cache entry exlusive, prevent any other cache from reading the data until instruction completes.