diff options
author | Björn Gustavsson <[email protected]> | 2014-02-28 06:34:43 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2014-02-28 08:04:04 +0100 |
commit | 63a653050b5e6ca28cde1e8616c840abafe71100 (patch) | |
tree | 07d3ab04eeea4ef290d739a9b8f4d9758fcbeeab /lib/kernel/test/topApp3.erl | |
parent | 81c7db0e247a6ee1b7a5c2764aa9575d7f6fb88a (diff) | |
download | otp-63a653050b5e6ca28cde1e8616c840abafe71100.tar.gz otp-63a653050b5e6ca28cde1e8616c840abafe71100.tar.bz2 otp-63a653050b5e6ca28cde1e8616c840abafe71100.zip |
Delay patching of closures to eliminate a race condition
The loader of native code tries to avoid race condition by bringing
down the system to a single scheduler. Unfortunately, that will not
completely avoid race conditions beacuse other processes may still
run while the code is being loaded. Therefore, we must still make
sure that native code has been fully fixed up before it can be
executed.
Under unlucky circumstances, it was possible for the global name
register process to call a fun in native code before the native
code for the fun had been fully fixed up. The run-time system
would crash when running the not-fully-fixed-up code.
Here is a way to make the bug 100% reproducible. First add this
function to the 'global' module:
silly_looper(List) ->
lists:foreach(fun(E) -> put(any_atom, E) end, List),
silly_looper(List).
Then insert the following code at the beginning of the init/1
function in the 'global' module:
spawn_link(fun() -> silly_looper(lists:seq(1, 100)) end),
The run-time system will crash during start up when the native
code for the 'global' module is being loaded. What will happen
is that lists:foreach/2 (which runs in native code) will call
the native code for the fun in silly_looper/1 before the reference
to 'any_atom' has been changed from a 0 to the proper tagged
atom value. The put/2 BIF will exit when attempting to calculate
the hash value for the illegal value 0 (it is not properly tagged).
To eliminate this race condition, we must delay patching the
native code addresses for a fun into the fun entry until the native
code has been fully fixed up. We will use the new BIFs introduced
in the previous commit.
While we are at it, we will also make sure that we erase any
temporary variables in the process dictionary used by the
hipe_unified_loader module.
Diffstat (limited to 'lib/kernel/test/topApp3.erl')
0 files changed, 0 insertions, 0 deletions