237
66
pthread_t thread;
67
pthread_mutex_init(&lock, NULL);
68
69
TX_BEGIN(pop) {
70
pthread_mutex_lock(&lock);
71
TOID(struct my_root) root
72
= POBJ_ROOT(pop, struct my_root);
73
TX_ADD(root);
74
pthread_create(&thread, NULL,
75
func, (void *) pop);
76
D_RW(root)->value = D_RO(root)->value + 4;
77
D_RW(root)->is_odd = D_RO(root)->value % 2;
78
pthread_mutex_unlock(&lock);
79
// wait to make sure other thread finishes 1st
80
pthread_join(thread, NULL);
81
} TX_END
82
83
pthread_mutex_destroy(&lock);
84
return 0;
85 }
• Line 69: The main thread starts a transaction and adds the root data
structure to it (line 73).
• Line 74: We create a new thread by calling pthread_create() and
have it execute the func() function. This function also starts a
transaction (line 51) and adds the root data structure to it (line 55).
• Both threads will simultaneously modify all or part of the same data
before finishing their transactions. We force the second thread to
finish first by making the main thread wait on pthread_join().
Listing 12-29 shows code execution with pmemcheck, and the result warns us that we
have overlapping regions registered in different transactions.
Chapter 12 Debugging persistent MeMory appliCations
Précédent

- 261/457

Suivant