[erlang-questions] erl_ddll:load_driver behaviour.
Tue Dec 11 01:27:31 CET 2012
On Mon, Dec 10, 2012 at 6:46 PM, Amit Kapoor <amit@REDACTED> wrote:
> Hi folks,
> Trying to understand load_drive behaviour. The test code I am using is at
> end of this email. The driver being loaded is a dummy driver with a printf
> message in the DRIVER_INIT code. If I call spawn:test(true,3), the printf
> message in DRIVER_INIT code gets displayed 3 times, whereas
> displays the same message only once. The erl_ddll manual is a bit lacking
> this area, so wanted to get some clarification.
> 1. Is this the expected behaviour?
This is expected because in the true case you're spawning a new process
that loads the driver, and when that process exits, the driver gets
unloaded. Near the top of the erl_ddll man page you can find this passage:
"The driver is always reference counted and as long as a process keeping
the driver loaded is still alive, the driver is present in the system."
If you go into an erlang shell and run the false case first, then run the
true case, the 3 true attempts will all get already_loaded because your
shell process already loaded the driver in the first false case, and
assuming that shell process is still alive, the true cases have no need to
> 2. Child processes seem to 'inherit' drivers loaded by parent process?
I don't think so. If the parent loads the driver and doesn't die, then the
driver remains loaded and the child will also be able to see the driver.
You can use erl_ddll:info(test_drv, processes) anytime after loading it to
see what processes have a ref count on it. For example, after running
spawn:test(false, 3) in your shell you'll see from erl_ddll:info(test_drv,
processes) that the shell process has a ref count of 3 on test_drv.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions