[sane-devel] pthread_detach after pthread_join generates segfault

Luiz Angelo Daros de Luca luizluca at gmail.com
Tue Aug 25 21:36:07 UTC 2015


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/sane-devel/attachments/20150825/2334b087/attachment.html>


More information about the sane-devel mailing list