[erlang-questions] What API should be used in port-drivers to guarantee thread-safety of driver_send_term and driver_output_term?

Lukas Larsson <>
Wed Sep 5 18:37:26 CEST 2012


Hello,

I do not think[1] this is a problem which you can solve in your
driver. It is probably the internals of the Erlang VM which are not
threadsafe, i.e. if there are no locks around message queues to
processes in the non-smp emulator. So while sending data to a process,
that same process could be reading data from the queue, and voila you
get a segfault. So in order to fix this I think you would have to
patch the emulator it self.

Lukas

[1]: Note that I haven't actually checked the relevant code, I have
divined this from what I know of the emulator.

On Wed, Sep 5, 2012 at 5:18 PM, Zhemzhitsky Sergey
<> wrote:
> Hi erlang gurus,
>
>
>
> We’re developing erlang port driver that will send different terms to some
> processes from the separate threads using driver_send_term.
>
> Each native thread started in the port driver (by means of
> erl_drv_thread_create) will be associated with only one erlang process and
> will send messages only to it.
>
>
>
> As a rule the documentation for driver_send_term says that it’s not
> thread-safe when smp is disabled, so we have tested the driver with disabled
> smp support and found that from time to time it leads to segfaults.
>
>
>
> So, the question is what is the proper way to make calls to driver_send_term
> (and driver_output_term) thread-safe?
>
> Will driver_pdl_lock, driver_pdl_unlock help?
>
> Will wrapping all the calls to driver_send_term (and driver_output_term)
> with erl_drv_mutex_lock and erl_drv_mutex_unlock help?
>
>
>
>
>
> Best Regards,
>
> Sergey
>
>
>
> _______________________________________________________
>
>
>
> The information contained in this message may be privileged and conf
> idential and protected from disclosure. If you are not the original intended
> recipient, you are hereby notified that any review, retransmission,
> dissemination, or other use of, or taking of any action in reliance upon,
> this information is prohibited. If you have received this communication in
> error, please notify the sender immediately by replying to this message and
> delete it from your computer. Thank you for your cooperation. Troika Dialog,
> Russia.
>
> If you need assistance please contact our Contact Center (+7495) 258 0500 or
> go to www.troika.ru/eng/Contacts/system.wbp
>
>
>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list