Memory Locking
Like databases, the operating system also locks memory. The terms match database locking. But the concept differs a bit.
- Pessimistic Locking- Lock the memory first. Release it only after the work is done. Example - Mutex, Semaphores, Reentrant Locks.
- Optimistic Locking - Do the work first. Check if the memory is still in the same state. If not, then retry or handle it based on the situation. Example - CAS (Compare and Swap) instruction, etc.