[erlang-questions] Port Driver. erl_drv_thread_join and ErlDrvTid reuse.
Wed Oct 10 21:12:33 CEST 2012
>>From time to time erl_drv_thread_join returns error EDEADLK=35, i.e. the current thread (scheduler thread) tries to join itself.
> According to the documentation “A Thread identifier may be reused very quickly after a thread has terminated. Therefore, if a thread corresponding to one of the involved thread identifiers has terminated since the thread identifier was saved, the result of erl_drv_equal_tids() might not give the expected result.”
> I suppose that thread terminates earlier then erl_drv_thread_join call happens, so ErlDrvTid is already reused.
This reuse will not cause problems for erl_drv_thread_join() as long as
it is used correctly (a tid wont be reused until after the thread has
been joined). erl_drv_thread_join() will also refuse to join threads not
created by erl_drv_thread_create(), and would in case the scheduler
thread tried to join itself fail with EINVAL.
> So the question is how to use erl_drv_thread_join properly and how to guarantee that the saved ErlDrvTid value points to the same data that was returned from erl_drv_thread_create?
It is important that the thread is joined once and *only* once. Are you
sure that you don't do two calls to erl_drv_thread_join() for the same
Rickard Green, Erlang/OTP, Ericsson AB.
More information about the erlang-questions