# Parallel Programming final notes ## 1. Terminologies ### Race condition >Race condition is a situation that occurs when two or more threads access a shared data at the same time. It can cause incorrect results "sometimes", therefore can be hard to debug. ![](https://i.stack.imgur.com/m7HYo.png) ### Critical section >Critical section is a segment of code, in which the process may update shared data. Mutual exclusion is kept among all critical sections in all threads, only one thread can enter critical section at a time. ### Atomic operations >Atomic operations are indivisible sequences of instructions. Nothing can interrupt the execution of an atomic command. ### Threads vs Processes > - A process is an instance of a running program. > - A thread is a subset of a process, or a lightweight process. > - Processes can have multiple threads (multi-threaded process). Threads of the same process share memory, but have individual stacks. ### False sharing >False sharing is a situation that degrades performance on multiprocessor CPU caches. Due to the size of a cache line being larger than a single word variable, data in the same cache line can't be accessed simultaneously by different threads, which causes extra cache misses. ## 2. Busy waiting >Busy waiting is a syncronization technique that has threads check for access repeatedly. It is wasteful of CPU resource. ## 3. ## 4.