Concurrent libpmemobj transactions

47 views
Skip to first unread message

Xinwei Fu

unread,
Oct 19, 2020, 4:01:12 PM10/19/20
to pmem
Hi, experts!

I am writing a concurrent data structures using libpmemobj transactions.
I got the following example from the book:
52  void increment(pop_type &pop) {
53      auto proot = pop.root();
54      pobj::transaction::run(pop, [&] {
55          proot->counter.get_rw() += 1;
56      }, proot->mtx);
57  }

Here is my understanding:
For two concurrent transactions which are racing to each other, I have to lock the whole transactions to guarantee mutual exclusion and there is no way to use fine-grained locks inside transactions.

Is my understanding correct?
Are there any other PMDK examples using concurrent transactions I can learn from?

Thanks,
-Xinwei 

--
Xinwei (Mason) Fu
PhD student, Computer Science, 2016-?
Virginia Tech

ppbb...@gmail.com

unread,
Oct 20, 2020, 9:00:24 AM10/20/20
to pmem
Mostly - yes. Using transaction-scope locks is the easiest approach. You can also acquire more locks inside of a transaction using `pmemobj_tx_lock` function. What this guarantees is that the locks are going to be held until the transaction is fully commited and won't be rolled back. This is important because you don't want other independent transactions to operate on a state that might be rolled back in the future - which could be the case if you were to acquire and drop locks inside of a transaction.

This is the most straightforward way of managing concurrent access to data, but obviously applications are free to use more complex solutions.
PMDK doesn't have many examples that use locks, but there are a couple:

I'd say is that as long as you understand that data access has transactional scope, then you only need to follow the normal rules of concurrent programming.
Reply all
Reply to author
Forward
0 new messages