Erlang supports change of code in a running system. Code replacement is done on module level.
The code of a module can exist in two variants in a system: current and old. When a module is loaded into the system for the first time, the code
becomes 'current'. If then a new instance of the module is loaded, the code of the previous instance becomes 'old' and the new instance becomes 'current'.
Both old and current code is valid, and may be evaluated concurrently. Fully qualified function calls always refer to current code. Old code may stil
be evaluated because of processes lingering in the old code.
If a third instance of the module is loaded, the code server will remove (purge) the old code and any processes lingering in it will be terminated.
Then the third instance becomes 'current' and the previously current code becomes 'old'.
To change from old code to current code, a process must make a fully qualified function call. Example:
-module(m).
-export([loop/0]).
loop() ->
receive
code_switch ->
m:loop();
Msg ->
...
loop()
end.
To make the process change code, send the message code_switch to it. The process then will make a fully qualified call to m:loop() and change to
current code. Note that m:loop/0 must be exported.
For code replacement of funs to work, the tuple syntax {Module,FunctionName} must be used to represent the fun.
Code Loading
The object code must be loaded into the Erlang runtime system. This is handled by the code server.
The code server loads code according to a code loading strategy which is either interactive (default) or embedded. In interactive mode, code are
searched for in a code path and loaded when first referenced. In embedded mode, code is loaded at start-up according to a boot script.
2009 March 30th Monday (三月 三十日 月曜日)
最新推荐文章于 2023-08-15 15:56:49 发布
Erlang支持在运行系统中更改代码,通过模块级别的代码替换实现。加载到系统的模块代码可以存在两种状态:当前版本和旧版本。当模块首次加载时,其代码成为'当前'版本。如果再次加载新实例,则之前的版本变为'旧'版本,而新加载的成为'当前'版本。两者皆为有效版本,可同时执行。
2119

被折叠的 条评论
为什么被折叠?



