<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; "><p style="font-family: Verdana, Arial, Helvetica, sans-serif; "><a name="driver_async%20"><span class="bold_code" style="font-family: courier; font-weight: bold; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: normal; "><p style="font-family: Verdana, Arial, Helvetica, sans-serif; "><a name="driver_async%20"><span class="bold_code" style="font-family: courier; font-weight: bold; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: normal; "><p style="font-family: Verdana, Arial, Helvetica, sans-serif; display: inline !important; ">Hello.</p><div><br></div><div>I have a question regarding erl_driver and the async thread pool.</div></span></span></a></p><p style="font-family: Verdana, Arial, Helvetica, sans-serif; "><a name="driver_async%20"><span class="bold_code" style="font-family: courier; font-weight: bold; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: normal; "><p style="font-family: Verdana, Arial, Helvetica, sans-serif; display: inline !important; ">Is it safe to call driver_output directly by an async thread?</p><div><br></div><div>From my limited testing, it works well. From the documentation, I'm not sure.</div></span></span></a></p><div>thanks,</div><div><br></div><div>- Joe N.</div><p style="font-family: Verdana, Arial, Helvetica, sans-serif; "><br></p></span></span></a></p><p><a name="driver_async%20"><span class="bold_code"><font class="Apple-style-span" face="courier"><b>http://www3.erlang.org/documentation/doc-5.5.5/erts-5.5.5/doc/html/erl_driver.html</b></font></span></a></p><p style="font-family: Verdana, Arial, Helvetica, sans-serif; "><a name="driver_async%20"><span class="bold_code" style="font-family: courier; font-weight: bold; "><br></span></a></p><p style="font-family: Verdana, Arial, Helvetica, sans-serif; "><a name="driver_async%20"><span class="bold_code" style="font-family: courier; font-weight: bold; ">long driver_async (ErlDrvPort port, unsigned int* key, void (*async_invoke)(void*), void* async_data, void (*async_free)(void*))</span></a><br></p><div class="REFBODY" style="margin-left: 13mm; "><p style="font-family: Verdana, Arial, Helvetica, sans-serif; "><a name="driver_async"></a></p><p style="font-family: Verdana, Arial, Helvetica, sans-serif; ">This function performs an asynchronous call. The function <span class="code" style="font-family: courier; font-weight: normal; ">async_invoke</span> is invoked in a thread separate from the emulator thread. This enables the driver to perform time-consuming, blocking operations without blocking the emulator.</p><div><br></div></div></span></div><div><p style="font-family: Verdana, Arial, Helvetica, sans-serif; "><a name="driver_output"><span class="bold_code" style="font-family: courier; font-weight: bold; ">int driver_output(ErlDrvPort port, char *buf, int len)</span></a><br></p><div class="REFBODY" style="margin-left: 13mm; font-family: Verdana, Arial, Helvetica, sans-serif; "><p style="font-family: Verdana, Arial, Helvetica, sans-serif; "><a name="driver_output"></a></p><p style="font-family: Verdana, Arial, Helvetica, sans-serif; ">The <span class="code" style="font-family: courier; font-weight: normal; ">driver_output</span> 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.</p><p style="font-family: Verdana, Arial, Helvetica, sans-serif; ">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.)</p><p style="font-family: Verdana, Arial, Helvetica, sans-serif; ">The parameter <span class="code" style="font-family: courier; font-weight: normal; ">buf</span> points to the data to send, and <span class="code" style="font-family: courier; font-weight: normal; ">len</span> is the number of bytes.</p><p style="font-family: Verdana, Arial, Helvetica, sans-serif; ">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.)</p><div><br></div></div></div><br><div>
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div>Joseph Wayne Norton</div><div><a href="mailto:norton@alum.mit.edu">norton@alum.mit.edu</a></div><div><br></div></span><br class="Apple-interchange-newline">
</div>
<br></body></html>