Erlang / Erlang Advanced Interview questions
What is the two-version code loading rule and what happens when a third version is loaded?
The BEAM keeps at most two versions of a module in memory at once: the current version, which new calls resolve to, and the old version, still executing for any process that was mid-loop when the reload happened. This bounded window is what allows hot code upgrades without an unbounded pile-up of stale code.
code:load_file(my_module). %% current becomes old, new module becomes current %% ... later ... code:load_file(my_module). %% loading a THIRD version
If a third version is loaded while some process is still running the old (now second-oldest) version, the
BEAM has nowhere to put it — so it forcibly kills any process still executing that stale version via
code:purge/1, then promotes the new version to current. This is why long-running loops are written
to periodically make a fully-qualified call back into themselves (e.g. ?MODULE:loop(State)): it
gives them a chance to pick up the newer code before a third reload force-terminates them.
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...
