<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content="MSHTML 6.00.2800.1106" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY
style="WORD-WRAP: break-word; khtml-nbsp-mode: space; khtml-line-break: after-white-space"
bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Thanks Tony.</FONT></DIV>
<DIV><FONT face=Arial size=2> Yep I used ready_async (<FONT
face="Times New Roman" size=3>async_ready?</FONT>) to signal erlang about
the completeion of async event.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>static void ready_async(ErlDrvData drv_data,
ErlDrvThreadData thread_data)<BR>{<BR> ThreadData * threadData =
(ThreadData *)thread_data;<BR> DriverData *dd = (DriverData *)
drv_data;<BR> ErlDrvTermData *ind;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>if (ind = (ErlDrvTermData *)driver_alloc(8 *
sizeof(ErlDrvTermData))) {<BR> ind[0] =
ERL_DRV_ATOM;<BR> ind[1] =
driver_mk_atom("speak_finished");<BR> ind[2] =
ERL_DRV_ATOM;<BR> ind[3] =
driver_mk_atom("ok");</FONT></DIV>
<DIV><FONT face=Arial size=2> ind[4] =
ERL_DRV_TUPLE;<BR> ind[5] = 2;</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><BR><FONT face=Arial
size=2> if(driver_output_term(dd->port,
ind, 6) < 1)<BR>
printf("driver_output_term failed\r\n");<BR>
else<BR> printf("driver_output_term
success\r\n");</FONT></DIV>
<DIV><FONT face=Arial
size=2> driver_free(ind);<BR>}<BR>else
{<BR> ----------</FONT></DIV>
<DIV><FONT face=Arial size=2>}<BR> </FONT></DIV>
<DIV><FONT face=Arial size=2> free(threadData);<BR>}</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>callTextToSpeech function is thread safe. Yes I
tried the same key argument but it gave me the same result. Also I issue the
other call after the ready_async.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2><STRONG>Please note I have a running system of the
same code with erlang release R10B-10. Upto now no issue. </STRONG></FONT></DIV>
<DIV><FONT face=Arial size=2><STRONG>But this problem is with erlang release
R11B-2.</STRONG> </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>How is it possible?</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><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<BLOCKQUOTE dir=ltr
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=tony@rogvall.com href="mailto:tony@rogvall.com">Tony Rogvall</A>
</DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=niranjan@wavenet.lk
href="mailto:niranjan@wavenet.lk">Niranjan Gunasekera</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Cc:</B> <A title=erlang-questions@erlang.org
href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</A>
</DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Wednesday, December 27, 2006 5:30
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> Re: [erlang-questions] Fw:
driver_async invoke leads to a segmentation fault</DIV>
<DIV><BR></DIV>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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><SPAN lang=EN-GB
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><O:P></O:P></SPAN></DIV>
<DIV style="MARGIN: 0in 0in 0pt"><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: 0in 0in 0pt"><SPAN lang=EN-GB
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><O:P></O:P></SPAN></DIV>
<DIV style="MARGIN: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt; 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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0in 0in 0pt"><SPAN lang=EN-GB><FONT size=3><FONT
face="Times New Roman"><O:P></O:P></FONT></FONT></SPAN></DIV>
<DIV style="MARGIN: 0in 0in 0pt"><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: 0in 0in 0pt"><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: 0px">_______________________________________________</DIV>
<DIV style="MARGIN: 0px">erlang-questions mailing list</DIV>
<DIV style="MARGIN: 0px">erlang-questions@erlang.org</DIV>
<DIV
style="MARGIN: 0px">http://www.erlang.org/mailman/listinfo/erlang-questions</DIV></BLOCKQUOTE></DIV><BR></DIV></BLOCKQUOTE></BODY></HTML>