221
54
munmap(ptr, 2 * sizeof(int));
55
return 0;
56 }
Listing 12-15. Example of reading from persistent memory with a write
dependency
33 #include
34 #include
35 #include
36
37 int main(int argc, char *argv[]) {
38
int fd, *ptr, *data, *flag;
39
40
fd = open("/mnt/pmem/file", O_CREAT|O_RDWR, 0666);
41
posix_fallocate(fd, 0, 2 * sizeof(int));
42
43
ptr = (int *) mmap(NULL, 2 * sizeof(int),
44
PROT_READ | PROT_WRITE,
45
MAP_SHARED_VALIDATE | MAP_SYNC,
46
fd, 0);
47
48
data = &(ptr[1]);
49
flag = &(ptr[0]);
50
if (*flag == 1)
51
printf("data = %d\n", *data);
52
53
munmap(ptr, 2 * sizeof(int));
54
return 0;
55 }
Checking our code with Persistence Inspector is done in three steps.
Step 1: We must run the before-unfortunate-event phase analysis (see Listing 12-16),
which corresponds to the writer code in Listing 12-14.
Chapter 12 Debugging persistent MeMory appliCations
Précédent

- 245/457

Suivant