A fact given by experiments: When a NIF aborted, it will terminate the entire Elixir abnormally, even if a supervisor monitors it.
mix new abort_nif --sup
cd abort_nif
- edit the following files.
mix.exs
lib/abort_nif/application.ex
lib/abort_nif.ex
Makefile
libnif.c
mix deps.get
iex -S mix
AbortNif
has push/1
and pop/0
functions:
iex(1)> AbortNif.pop()
:empty
iex(2)> AbortNif.push(1)
:ok
iex(3)> AbortNif.push(2)
:ok
iex(4)> AbortNif.pop()
2
iex(5)> AbortNif.pop()
1
iex(6)> AbortNif.pop()
:empty
AbortNif
aborts by abort_soft/0
and restart soon by the supervisor.
The state will be empty by restarting:
iex(1)> AbortNif.push(1)
:ok
iex(2)> AbortNif.push(2)
:ok
iex(3)> AbortNif.abort_soft()
:ok
iex(4)> AbortNif.pop()
:empty
AbortNif
aborts by abort_hard/0
by NIF, but it will terminate the entire Elixir abnormally, even if the supervisor monitors it.
iex(1)> AbortNif.push(1)
:ok
iex(2)> AbortNif.push(2)
:ok
iex(3)> AbortNif.abort_hard()
zsh: abort iex -S mix
%
%