Keywords: perfbook_html

#### 14.2.12.1.2 LOCK-Based Critical Sections:

Although a LOCK-UNLOCK pair does not act as a full memory barrier, these operations do affect memory ordering.

Consider the following code:

      1 *A = a;
      2 *B = b;
      3 LOCK
      4 *C = c;
      5 *D = d;
      6 UNLOCK
      7 *E = e;
      8 *F = f;

This could legitimately execute in the following order, where pairs of operations on the same line indicate that the CPU executed those operations concurrently:

      3 LOCK
      1 *A = a; *F = f;
      7 *E = e;
      4 *C = c; *D = d;
      2 *B = b;
      6 UNLOCK

Table: Lock-Based Critical Sections
# | Ordering: legitimate or not?
1 | *A; *B; LOCK; *C; *D; UNLOCK; *E; *F;
2 | `*A; *B; LOCK; *C; *D; UNLOCK; *E; *F;`
3 | `*F; *A; *B; LOCK; *C; *D; UNLOCK; *E;`
4 | `*A; *B; LOCK; *C; *D; UNLOCK; *E; *F;`
5 | *B; LOCK; *C; *D; *A; UNLOCK; *E; *F;
6 | *A; *B; *C; LOCK; *D; UNLOCK; *E; *F;
7 | *A; *B; LOCK; *C; UNLOCK; *D; *E; *F;
8 | `*B; *A; LOCK; *D; *C; UNLOCK; *F; *E;`
9 | `*B; LOCK; *C; *D; UNLOCK; *F; *A; *E;`

Quick Quiz 14.13: Given that operations grouped in curly braces are executed concurrently, which of the rows of Table are legitimate reorderings of the assignments to variables ``A'' through ``F'' and the LOCK/UNLOCK operations? (The order in the code is A, B, LOCK, C, D, UNLOCK, E, F.) Why or why not? End Quick Quiz