229
45 int main(int argc, char *argv[]) {
46
// creating the pool
47
PMEMobjpool *pop= pmemobj_create("/mnt/pmem/pool",
48
POBJ_LAYOUT_NAME(example),
49
(1024 * 1024 * 100), 0666);
50
51
// transation
52
TX_BEGIN(pop) {
53
TOID(struct my_root) root
54
= POBJ_ROOT(pop, struct my_root);
55
56
// adding root.value to the transaction
57
TX_ADD_FIELD(root, value);
58
59
D_RW(root)->value = 4;
60
D_RW(root)->is_odd = D_RO(root)->value % 2;
61
} TX_END
62
63
return 0;
64 }
Note For a refresh on the definitions of a layout, root object, or macros used in
listing 12-21, see Chapter 7 where we introduce libpmemobj.
In lines 35-38, we create a my_root data structure, which has two integer members:
value and is_odd. These integers are modified inside a transaction (lines 52-61),
setting value=4 and is_odd=0. On line 57, we are only adding the value variable to the
transaction, leaving is_odd out. Given that persistent memory is not natively supported
in C, there is no way for the compiler to warn you about this. The compiler cannot
distinguish between pointers to volatile memory vs. those to persistent memory.
Listing 12-22 shows the response from running the code through pmemcheck.
Chapter 12 Debugging persistent MeMory appliCations
Précédent

- 253/457

Suivant