We'll start on threads early Multicore CPUs Seems simple: Just put a bunch of CPU dies together EPYC page: https://en.wikipedia.org/wiki/Epyc Cache: L1: Specific to a core L2: Shared between cores maybe ChatGPT thought so AMD 9000 series has per-core L2 L3: More shared So...each thread should have its own registers And stack? Where are their stacks? Can a thread access another thread's stack? Do they have the same heap? Can a thread allocate something and another thread free it? What happens if one thread calls exit? Do they really run at the same time at nanosecond precision? clock_gettime Let's see if we can answer all these questions! pthreads library: Allows us to run our program from more than one place at once Simple example: pthread_create Just make it do two things at once C or C++? For this example, cout is about all that's different Speedup: Could be questionable! Depends on the task Race Conditions: Something that varies based on timing We can engineer one easy enough Use random and usleep maybe? Remember to seed it Preventing race conditions: A mutex Mutual Exclusion There are other things here (atomic operations, etc) but mutex is enough for now Project 5: This should speed up ok Too many threads might get in the way, depending on how you do it A sample problem: I did image filters last time