<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; ">Hi!<DIV><BR class="khtml-block-placeholder"></DIV><DIV>Have you used/seen the async_ready callback. The async_ready is called when the call is completed, and</DIV><DIV>is called in the main thread. Here is the place to signal back to the Erlang application making the call/cast</DIV><DIV>that the call is completed.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Also the way you do the call, you must make sure that the function callTextToSpeech is thread safe, since you</DIV><DIV>may have multiple instances running at the same time (at least from what I can see in the code fragement).</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>You can synchronize either:</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>a) Use the same key argument (not NULL) to make sure the same thread is used for the calll</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>b) Do not issue an other call before async_ready is called.</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>c) Make everything thread safe.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Regards</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>/Tony</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR><DIV><DIV>On 27 dec 2006, at 03.48, Niranjan Gunasekera wrote:</DIV><BR class="Apple-interchange-newline"><BLOCKQUOTE type="cite"> <DIV><FONT face="Arial" size="2">Can anybody help, please</FONT></DIV> <DIV><FONT face="Arial" size="2"></FONT> </DIV> <DIV><FONT face="Arial" size="2"></FONT> </DIV> <DIV><FONT face="Arial" size="2">Thanks</FONT></DIV> <DIV><FONT face="Arial" size="2">Niranjan Gunasekera</FONT></DIV> <DIV style="FONT: 10pt arial">----- Original Message ----- <DIV style="BACKGROUND: #e4e4e4; font-color: black"><B>From:</B> <A title="niranjan@wavenet.lk" href="mailto:niranjan@wavenet.lk">Niranjan Gunasekera</A> </DIV> <DIV><B>To:</B> <A title="erlang-questions@erlang.org" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</A> </DIV> <DIV><B>Sent:</B> Friday, December 22, 2006 9:06 AM</DIV> <DIV><B>Subject:</B> [erlang-questions] driver_async invoke leads to a segmentation fault</DIV></DIV> <DIV><BR></DIV> <DIV><FONT face="Arial" size="2"><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Hi all,</SPAN><SPAN lang="EN-GB"><O:P></O:P></SPAN></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> I’m using erlang driver_async to invoke a function asynchronously. First reference to the function ‘driver_async’ works fine. But next reference to the same call leads to a segmentation fault. I’m using erlang release R11B-2. Same code works fine with erlang release R10B-10. Is it a problem with erlang release?<O:P></O:P></SPAN></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><O:P> </O:P></SPAN></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Is it a problem with coding?<O:P></O:P></SPAN></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><O:P> </O:P></SPAN></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">static int control(ErlDrvData drv_data, unsigned int command, char *buf, int len, char **rbuf, int rlen)<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">{<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; text-indent: 0.5in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">--------<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-tab-count: 1"> </SPAN>--------<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-tab-count: 1"> </SPAN>DriverData *dd = (DriverData *) drv_data;<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-tab-count: 1"> </SPAN>set_port_control_flags(dd->port, PORT_CONTROL_FLAG_BINARY);<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-tab-count: 1"> </SPAN>ThreadData *threadData;<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-tab-count: 1"> </SPAN>if((threadData = (ThreadData *) driver_alloc(sizeof(ThreadData))) == NULL) {<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-tab-count: 2"> </SPAN>error = 1;<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-tab-count: 1"> </SPAN>}<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-tab-count: 1"> </SPAN>else {<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-tab-count: 2"> </SPAN>error = 0;<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-tab-count: 2"> </SPAN>memset(threadData, 0, sizeof(threadData));<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-tab-count: 2"> </SPAN>if((threadData->input = (char *) driver_alloc(len + 1)) == NULL) {<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-tab-count: 3"> </SPAN>free(threadData);<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-tab-count: 3"> </SPAN>error = 1;<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-tab-count: 2"> </SPAN>}<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-tab-count: 2"> </SPAN>else {<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-tab-count: 3"> </SPAN>---------<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-tab-count: 3"> </SPAN>---------<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-tab-count: 3"> </SPAN><B style="mso-bidi-font-weight: normal">driver_async(dd->port, NULL, callTextToSpeech, (void *)threadData, freeThreadData);<SPAN style="mso-tab-count: 1"> </SPAN>//first call to this function works fine<O:P></O:P></B></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-tab-count: 2"> </SPAN>}<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-tab-count: 1"> </SPAN>}<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><O:P> </O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-tab-count: 1"> </SPAN>}<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-tab-count: 1"> </SPAN>if (error)<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-tab-count: 2"> </SPAN>gen_error_reply(rbuf, rlen, &rindex, "driver_alloc_failiure", 0);<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-tab-count: 1"> </SPAN>else<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-tab-count: 2"> </SPAN>gen_ok_reply(rbuf, rlen, &rindex);<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><I style="mso-bidi-font-style: normal"><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">}<O:P></O:P></SPAN></I></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><SPAN lang="EN-GB"><FONT size="3"><FONT face="Times New Roman"> <O:P></O:P></FONT></FONT></SPAN></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Thanks</SPAN><SPAN lang="EN-GB"><O:P></O:P></SPAN></DIV><DIV style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "><SPAN lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Niranjan Gunasekera</SPAN><SPAN lang="EN-GB"><O:P></O:P></SPAN></DIV></FONT></DIV><DIV> <BR class="khtml-block-placeholder"></DIV><HR><DIV><BR class="khtml-block-placeholder"></DIV>_______________________________________________<BR>erlang-questions mailing list<BR><A href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</A><BR>http://www.erlang.org/mailman/listinfo/erlang-questions<BR><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">_______________________________________________</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">erlang-questions mailing list</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">erlang-questions@erlang.org</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">http://www.erlang.org/mailman/listinfo/erlang-questions</DIV> </BLOCKQUOTE></DIV><BR></DIV></BODY></HTML>