Database / Mnesia intermediate to advanced Interview questions
What is the difference between a global lock and a per-record lock in Mnesia transactions?
A per-record lock (the default behavior of read/1/write/1 inside a transaction)
only blocks other transactions from touching that specific record, letting unrelated concurrent transactions
on other records in the same table proceed freely. A global (table-level) lock, taken via
mnesia:read_lock_table/1 or mnesia:write_lock_table/1, blocks access to the
entire table for the duration of the transaction.
| Per-record lock | Table-level lock |
| Only affects the specific record being read/written. | Affects every record in the table. |
| Maximizes concurrency for unrelated operations. | Serializes all access to the table, sacrificing concurrency. |
| Default behavior for normal read/write. | Requires explicitly calling a table-lock function. |
Table-level locks trade away most of the concurrency benefit of fine-grained locking, so they're reserved for operations that genuinely need a consistent view of, or exclusive access to, the whole table at once.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
