[erlang-questions] Fw: driver_async invoke leads to a segmentation fault

Niranjan Gunasekera niranjan@REDACTED
Wed Dec 27 12:19:44 CET 2006


Thanks Tony.
    Yep I used ready_async (async_ready?) to signal erlang about the completeion of async event.

static void ready_async(ErlDrvData drv_data, ErlDrvThreadData thread_data)
{
 ThreadData * threadData = (ThreadData *)thread_data;
 DriverData *dd = (DriverData *) drv_data;
 ErlDrvTermData *ind;

if (ind = (ErlDrvTermData *)driver_alloc(8 * sizeof(ErlDrvTermData))) {
     ind[0] = ERL_DRV_ATOM;
     ind[1] = driver_mk_atom("speak_finished");
     ind[2] = ERL_DRV_ATOM;
     ind[3] = driver_mk_atom("ok");
     ind[4] = ERL_DRV_TUPLE;
     ind[5] = 2;


      if(driver_output_term(dd->port, ind, 6) < 1)
        printf("driver_output_term failed\r\n");
     else
        printf("driver_output_term success\r\n");
     driver_free(ind);
}
else {
     ----------
}
 
   free(threadData);
}



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.

Please note I have a running system of the same code with erlang release R10B-10. Upto now no issue. 
But this problem is with erlang release R11B-2. 

How is it possible?

Thanks
Niranjan Gunasekera






  ----- Original Message ----- 
  From: Tony Rogvall 
  To: Niranjan Gunasekera 
  Cc: erlang-questions@REDACTED 
  Sent: Wednesday, December 27, 2006 5:30 PM
  Subject: Re: [erlang-questions] Fw: driver_async invoke leads to a segmentation fault


  Hi!


  Have you used/seen the async_ready callback. The async_ready is called when the call is completed, and
  is called in the main thread. Here is the place to signal back to the Erlang application making the call/cast
  that the call is completed.


  Also the way you do the call, you must make sure that the function callTextToSpeech is thread safe, since you
  may have multiple instances running at the same time (at least from what I can see in the code fragement).


  You can synchronize either:


  a) Use the same key argument (not NULL) to make sure the same thread is used for the calll
  b) Do not issue an other call before async_ready is called.
  c) Make everything thread safe.


  Regards


  /Tony








  On 27 dec 2006, at 03.48, Niranjan Gunasekera wrote:


    Can anybody help, please


    Thanks
    Niranjan Gunasekera
    ----- Original Message ----- 
    From: Niranjan Gunasekera 
    To: erlang-questions@REDACTED 
    Sent: Friday, December 22, 2006 9:06 AM
    Subject: [erlang-questions] driver_async invoke leads to a segmentation fault


    Hi all,
        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?

    Is it a problem with coding?

    static int control(ErlDrvData drv_data, unsigned int command, char *buf, int len, char **rbuf, int rlen)
    {
    --------
                --------
                DriverData *dd = (DriverData *) drv_data;
                set_port_control_flags(dd->port, PORT_CONTROL_FLAG_BINARY);
                ThreadData *threadData;
                if((threadData = (ThreadData *) driver_alloc(sizeof(ThreadData))) == NULL) {
                            error = 1;
                }
                else {
                            error = 0;
                            memset(threadData, 0, sizeof(threadData));
                            if((threadData->input = (char *) driver_alloc(len + 1)) == NULL) {
                                        free(threadData);
                                        error = 1;
                            }
                            else {
                                        ---------
                                        ---------
                                        driver_async(dd->port, NULL, callTextToSpeech, (void *)threadData, freeThreadData);  //first call to this function works fine
                            }
                }

                }
                if (error)
                            gen_error_reply(rbuf, rlen, &rindex, "driver_alloc_failiure", 0);
                else
                            gen_ok_reply(rbuf, rlen, &rindex);
    }

    Thanks
    Niranjan Gunasekera



----------------------------------------------------------------------------



    _______________________________________________
    erlang-questions mailing list
    erlang-questions@REDACTED
    http://www.erlang.org/mailman/listinfo/erlang-questions

    _______________________________________________
    erlang-questions mailing list
    erlang-questions@REDACTED
    http://www.erlang.org/mailman/listinfo/erlang-questions

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20061227/685bb7ad/attachment.htm>


More information about the erlang-questions mailing list