236
Listing 12-28. Example of two threads simultaneously adding the same
persistent memory location to their respective transactions
33 #include
34 #include
35
36 struct my_root {
37
int value;
38
int is_odd;
39 };
40
41 POBJ_LAYOUT_BEGIN(example);
42 POBJ_LAYOUT_ROOT(example, struct my_root);
43 POBJ_LAYOUT_END(example);
44
45 pthread_mutex_t lock;
46
47 // function to be run by extra thread
48 void *func(void *args) {
49
PMEMobjpool *pop = (PMEMobjpool *) args;
50
51
TX_BEGIN(pop) {
52
pthread_mutex_lock(&lock);
53
TOID(struct my_root) root
54
= POBJ_ROOT(pop, struct my_root);
55
TX_ADD(root);
56
D_RW(root)->value = D_RO(root)->value + 3;
57
pthread_mutex_unlock(&lock);
58
} TX_END
59 }
60
61 int main(int argc, char *argv[]) {
62
PMEMobjpool *pop= pmemobj_create("/mnt/pmem/pool",
63
POBJ_LAYOUT_NAME(example),
64
(1024 * 1024 * 10), 0666);
65
Chapter 12 Debugging persistent MeMory appliCations
Précédent

- 260/457

Suivant