[erlang-questions] erl_driver - is it safe to call driver_output directly by an async thread?

Joseph Wayne Norton <>
Wed Mar 30 18:15:36 CEST 2011


I have a question regarding erl_driver and the async thread pool.

Is it safe to call driver_output directly by an async thread?

From my limited testing, it works well.   From the documentation, I'm not sure.


- Joe N.


long driver_async (ErlDrvPort port, unsigned int* key, void (*async_invoke)(void*), void* async_data, void (*async_free)(void*))

This function performs an asynchronous call. The function async_invoke is invoked in a thread separate from the emulator thread. This enables the driver to perform time-consuming, blocking operations without blocking the emulator.

int driver_output(ErlDrvPort port, char *buf, int len)

The driver_output function is used to send data from the driver up to the emulator. The data will be received as terms or binary data, depending on how the driver port was opened.

The data is queued in the port owner process' message queue. Note that this does not yield to the emulator. (Since the driver and the emulator runs in the same thread.)

The parameter buf points to the data to send, and len is the number of bytes.

The return value for all output functions is 0. (Unless the driver is used for distribution, in which case it can fail and return -1. For normal use, the output function always returns 0.)

Joseph Wayne Norton

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110331/580148a2/attachment.html>

More information about the erlang-questions mailing list