[erlang-questions] Linked in drivers and locks

Jan Klötzke jan@REDACTED
Tue Nov 1 10:47:38 CET 2011


I'm hunting a bug in my linked in driver 
(https://github.com/jkloetzke/erldokan) which randomly locks up the emulator. 
While reviewing the code and the erl_driver documentation I came across the 
following paragraph in the docs:

  NOTE: When executing in an emulator thread, it is very important that you
  unlock all locks you have locked before letting the thread out of your
  control; otherwise, you are very likely to deadlock the whole emulator.

I'm not sure if I fully understand this. IMHO it's perfectly clear that you 
have to release any locks before leaving any of the emulator callbacks. But is 
this also true when calling back into the emulator?

Or to make it more specific this is the (simplified) code I'm pondering on:

static void ready_output(ErlDrvData handle, ErlDrvEvent event)
	struct self *self = (struct self *)handle;




static void outputv(ErlDrvData handle, ErlIOVec *ev)
	struct self *self = (struct self *)handle;


static ErlDrvEntry dokan_driver_entry = {
	.driver_name     = "erldokan_drv",
	.init            = init,
	.start           = start,
	.stop            = stop,
	.call            = call,
	.outputv         = outputv,
	.ready_input     = ready_input,
	.ready_output    = ready_output,
	.extended_marker = ERL_DRV_EXTENDED_MARKER,
	.driver_flags    = ERL_DRV_FLAG_USE_PORT_LOCKING,
	.stop_select     = stop_select,

Could this possibly lead to a deadlock?

PeerDrive - Beyond online storage

Store, sync, backup and organize your   http://peerdrive.org
data everywhere without relying on a    http://github.com/jkloetzke/peerdrive
permanent network connection.

More information about the erlang-questions mailing list