Locking
Learning xv6-riscv-book Chapter 5 Locking
Concurrency
: situations in which multiple instruction sreams are interleaved, due to multiprocessor parallelism, threasd switching, or interrupts.
Concurrency control
: strategies aimed at correctness under concurrency.
Lock
: provides mutual exclusion – ensurign that only one CPU at a time can hold the lock.
Race conditions
Race condition:
- a memory location is accessed concurrently
- at list one write
E.g. two CPUs execute list.push at the same time:
struct element {
int data;
struct element *next;
};
struct element *list = 0;
void
push(int data)
{
struct element *l;
l = malloc(sizeof *l