A spinlock named mutex may be used to protect a variable counter as follows:
spin_lock(&mutex); counter++; spin_unlock(&mutex); |
Quick Quiz B.2: What problems could occur if the variable counter were incremented without the protection of mutex? End Quick Quiz
However, the spin_lock() and spin_unlock() primitives
do have performance consequences, as will be seen in
Section .