[sane-devel] pthread_detach after pthread_join generates segfault

m. allan noah kitno455 at gmail.com
Wed Aug 26 00:53:11 UTC 2015


I'm no expert either, but your basic analysis seems correct- once you
have returned from pthread_join(), the thread is gone, and its return
value has been popped. I suppose it is possible that the pthread_join
could fail in a way that might leave the thread running, perhaps
because of a deadlock? In that case I suppose we could call
pthread_detatch only if there is an error?

Gerhard- do you remember anything about commit
0fb34bb098f1cbdd9d154328cb7f9d45ed8f6256 ?

allan

On Tue, Aug 25, 2015 at 5:36 PM, Luiz Angelo Daros de Luca
<luizluca at gmail.com> wrote:
> Hello,
>
> I was getting a segfault for sane-backends when using device sane-test. This
> happened when I compiled sane with uclibc or musl (on openwrt).
>
> I debugged the problem and traced it to sanei_thread_waitpid (at
> sanei/sanei_thread.c). It seems that calling pthread_detach after someone
> already did a pthread_join causes a segfault.
>
> I'm no pthread expert but I guess that after a pthread_join, the thread
> becomes "detached" and "terminated".
>
> And, according to man page PTHREAD_DETACH(3):
>
> "Attempting to detach an already detached thread results in unspecified
> behavior."
>
> I simply removed these detach lines in order to solve my problem. What would
> be the correct fix? Is there any case when join fails and detach is still
> valid? I checked error codes and only EDEADLK(when the thread is already
> waiting for the caller) and EINVAL (when three is another thread is already
> waiting for it) are possible situations when detach might do something. Are
> they possible in sane thread usage? If so, I guess detach might only be
> called when one of the possible fails of join happens.
>
> Regards,
>
> Luiz Angelo Daros de Luca
>
> --
> sane-devel mailing list: sane-devel at lists.alioth.debian.org
> http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/sane-devel
> Unsubscribe: Send mail with subject "unsubscribe your_password"
>              to sane-devel-request at lists.alioth.debian.org



-- 
"well, I stand up next to a mountain- and I chop it down with the edge
of my hand"



More information about the sane-devel mailing list