Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Port Driver. erl_drv_thread_join and ErlDrvTid reuse.
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Rickard Green  
View profile  
 More options Oct 10 2012, 3:12 pm
From: Rickard Green <rick...@erlang.org>
Date: Wed, 10 Oct 2012 21:12:33 +0200
Local: Wed, Oct 10 2012 3:12 pm
Subject: Re: [erlang-questions] Port Driver. erl_drv_thread_join and ErlDrvTid reuse.

>>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
thread?

Regards,
Rickard
--
Rickard Green, Erlang/OTP, Ericsson AB.
_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Zhemzhitsky Sergey  
View profile  
 More options Oct 11 2012, 8:21 am
From: Zhemzhitsky Sergey <sergey_zhemzhit...@sberbank-cib.ru>
Date: Thu, 11 Oct 2012 12:21:12 +0000
Local: Thurs, Oct 11 2012 8:21 am
Subject: Re: [erlang-questions] Port Driver. erl_drv_thread_join and ErlDrvTid reuse.
Hello Rickard,

Thanks a lot for clarification.

I'm doing erl_drv_thread_join() only once and only for threads created by erl_drv_thread_create().

The error only happens from time to time in the following scenario:

1. Erlang process, I send messages from the ddriver to, dies for some reason
2. Driver callback process_exit fires.
3. From the driver thread I'm trying to send the final message to the dead erlang process with driver_send_term
4. As the erlang process is dead, driver_send_term fails
5. As driver_send_term fails I'm doing driver_failure_atom to kill linked process.

Here two things happen:

6.1 (*stop)(ErlDrvData drv_data) executes as linked process has been killed by driver_failure_atom
6.2 Thread, started in the driver, exists

When (*stop)(ErlDrvData drv_data) executes erl_drv_thread_join is called for all the threads started in the driver.

So something wrong happens that leads to tid reuse.

Best Regards,
Sergey


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rickard Green  
View profile  
 More options Oct 11 2012, 8:35 am
From: Rickard Green <rick...@erlang.org>
Date: Thu, 11 Oct 2012 14:35:23 +0200
Local: Thurs, Oct 11 2012 8:35 am
Subject: Re: [erlang-questions] Port Driver. erl_drv_thread_join and ErlDrvTid reuse.
The tid cannot be prematurely reused in this case. The EDEADLK is due to
some other reason.

Are you calling driver_failure_atom() from your thread? That would
explain this issue.

Regards,
Rickard

On 10/11/2012 02:21 PM, Zhemzhitsky Sergey wrote:

--
Rickard Green, Erlang/OTP, Ericsson AB.
_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Zhemzhitsky Sergey  
View profile  
 More options Oct 11 2012, 9:11 am
From: Zhemzhitsky Sergey <sergey_zhemzhit...@sberbank-cib.ru>
Date: Thu, 11 Oct 2012 13:11:14 +0000
Local: Thurs, Oct 11 2012 9:11 am
Subject: Re: [erlang-questions] Port Driver. erl_drv_thread_join and ErlDrvTid reuse.
Hi Rickard,

>> Are you calling driver_failure_atom() from your thread? That would explain this issue.

Exactly. Could you explain a little bit more why it can cause this issue (I suppose it's due to it is not thread safe)?

Best Regards,
Sergey Zhemzhitsky
Phone. +7 495 2580500 ext. 1246


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rickard Green  
View profile  
 More options Oct 11 2012, 10:13 am
From: Rickard Green <rick...@erlang.org>
Date: Thu, 11 Oct 2012 16:13:08 +0200
Local: Thurs, Oct 11 2012 10:13 am
Subject: Re: [erlang-questions] Port Driver. erl_drv_thread_join and ErlDrvTid reuse.

On 10/11/2012 03:11 PM, Zhemzhitsky Sergey wrote:

> Hi Rickard,

>>> Are you calling driver_failure_atom() from your thread? That would explain this issue.

> Exactly. Could you explain a little bit more why it can cause this issue (I suppose it's due to it is not thread safe)?

Yes, it is because driver_failure_atom() is not thread safe. Apart from
misc thread unsafe modifications of the port internal state,
driver_failure_atom() can call the stop() callback which means that your
thread will end up trying to join with itself.

Regards,
Rickard
--
Rickard Green, Erlang/OTP, Ericsson AB.
_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Zhemzhitsky Sergey  
View profile  
 More options Oct 11 2012, 10:17 am
From: Zhemzhitsky Sergey <sergey_zhemzhit...@sberbank-cib.ru>
Date: Thu, 11 Oct 2012 14:17:25 +0000
Local: Thurs, Oct 11 2012 10:17 am
Subject: Re: [erlang-questions] Port Driver. erl_drv_thread_join and ErlDrvTid reuse.
Thanks a lot. Now it's clear enough.

Best Regards,
Sergey


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »