249
Listing 12-37. Pseudocode showcasing an out-of-order issue
1 writer () {
2
pcounter = 0;
3
flush (pcounter);
4
for (i=0; i
5
pcounter++;
6
if (rand () % 2 == 0) {
7
pcells[i].data = data ();
8
flush (pcells[i].data);
9
pcells[i].valid = True;
10
} else {
11
pcells[i].valid = False;
12
}
13
flush (pcells[i].valid);
14
}
15
flush (pcounter);
16 }
17
18 reader () {
19
for (i=0; i
20
if (pcells[i].valid == True) {
21
print (pcells[i].data);
22
}
23
}
24 }
For simplicity, assume that all flushes in Listing 12-37 are also synchronization
points; that is, flush() uses CLFLUSH. The logic of the program is very simple. There are
two persistent memory variables: pcells and pcounter. The first is an array of tuples
{data, valid} where data holds the data and valid is a flag indicating if data is valid
or not. The second variable is a counter indicating how many elements in the array have
been written correctly to persistent memory. In this case, the valid flag is not the one
indicating whether or not the array position was written correctly to persistent memory.
In this case, the flag’s meaning only indicates if the function data() was called, that is,
whether or not data has meaningful data.
Chapter 12 Debugging persistent MeMory appliCations
Listing 12-37. Pseudocode showcasing an out-of-order issue
1 writer () {
2
pcounter = 0;
3
flush (pcounter);
4
for (i=0; i
pcounter++;
6
if (rand () % 2 == 0) {
7
pcells[i].data = data ();
8
flush (pcells[i].data);
9
pcells[i].valid = True;
10
} else {
11
pcells[i].valid = False;
12
}
13
flush (pcells[i].valid);
14
}
15
flush (pcounter);
16 }
17
18 reader () {
19
for (i=0; i
if (pcells[i].valid == True) {
21
print (pcells[i].data);
22
}
23
}
24 }
For simplicity, assume that all flushes in Listing 12-37 are also synchronization
points; that is, flush() uses CLFLUSH. The logic of the program is very simple. There are
two persistent memory variables: pcells and pcounter. The first is an array of tuples
{data, valid} where data holds the data and valid is a flag indicating if data is valid
or not. The second variable is a counter indicating how many elements in the array have
been written correctly to persistent memory. In this case, the valid flag is not the one
indicating whether or not the array position was written correctly to persistent memory.
In this case, the flag’s meaning only indicates if the function data() was called, that is,
whether or not data has meaningful data.
Chapter 12 Debugging persistent MeMory appliCations
