Atomic variables in Linux
Consider the following program below, try to guess why the output is not 1,00,000 Code: Output: The reason behind it is giving different values each time is SMP Machine. In a multi processor system, global++ will be converted to global = global + 1. Steps to increment the value of global by 1: 1. Processor reads the value of global 2. Processor increments the value in memory 3. Processor writes the new value to global Let's take the example of global value is 5, and there are two processors in system , Processor 1 and Processor 2. Processor 1 reads the value of global and it is 5. Processor 1 increments the value in memory and make it 6 Processor 2 acquires the bus and reads the value of global and it will be 5 Processor 2 increments the value in memory and make it 6 Processor 1 comes and then writes 6 to global variable Processor 2 comes and then writes 6 to global variable. How to solve this problem? The simultaneous access problem...