7.1. Overview
During the advent of computing, computers had only one CPU. These CPUs got faster and faster (1,000 times in 20 years), but the increasing speed reached a limit. Since about 2010, Intel x86 CPUs haven’t gotten much faster. So, to increase computing power, more than one CPU was included in each computer. Today, one CPU chip contains many cores, and the number of cores in CPUs and computers is increasing.
In a computer, two or more threads may simultaneously access the same area of memory. Also, two or more processes can simultaneously access the same area of shared memory without using threads. CPUs work the calculations done in registers, and the content of these registers is read from and written to the main storage. That means intermediate results are for certain times in registers, and each thread has its own set of them. So, storing intermediate results in memory from two or more cores may lead to corrupted data. Also, when a computer has only one CPU, memory corruption may happen when threads are interrupted at a certain position. As a solution for these problems, the instruction CAS – compare and swap – is implemented in CPUs.