Database / Mnesia basics Interview questions
What is a Mnesia table lock and how does it work?
Inside a transaction, Mnesia automatically acquires locks on the specific records (or, in some cases, the whole table) a transaction touches, so concurrent transactions can't corrupt each other's view of the data. Reads take a read lock; writes take a write lock, which is exclusive and blocks other transactions from reading or writing that same record until the holding transaction commits or aborts.
sequenceDiagram
participant T1
participant T2
participant Record
T1->>Record: write lock acquired
T2->>Record: attempts write, must wait
T1->>Record: transaction commits, lock released
Record-->>T2: lock granted, T2 proceeds
You don't request locks explicitly in ordinary code — mnesia:read/1 and
mnesia:write/1 acquire the appropriate lock automatically as part of running inside a transaction.
If two transactions would deadlock waiting on each other's locks, Mnesia detects it and aborts one of them,
which the calling code should be prepared to retry.
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...
