bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Android/Termux pthread_cancel


From: Bruno Haible
Subject: Re: Android/Termux pthread_cancel
Date: Fri, 11 May 2018 02:07:43 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-119-generic; KDE/5.18.0; x86_64; ; )

Hi Paul,

> Thanks for the explanation. Does the attached Gnulib patch fix things for you?

The patch is surely good for Android. But the tricky part is to make sure
such a patch introduces no regression on the other platforms. And in fact,
this one does on FreeBSD 11, for the same reason we had to avoid 'phread_kill'
as witness symbol.

For this business of detecting whether libpthread is in use, we need to
consider all platforms on which USE_POSIX_THREADS_WEAK gets defined to 1.
These are:

A* Linux/glibc
B* Linux/musl
C* Hurd
D* GNU/kFreeBSD
E* FreeBSD, DragonFly
F* NetBSD
G* OpenBSD
H* HP-UX on ia64
I* IRIX
J* Solaris
K* Haiku
L* Android

So let's see in which library (libc vs. libpthread) the symbols are
defined.

Legend: C = libc, P = libpthread, - = not defined

                                A* B* C* D* E* F* G* H* I* J* K* L*

pthread_atfork                  P  C  P  P  P  C  -  P  P  C  C  C
pthread_attr_destroy            P  C  P  P  P  P  P  P  P  P  C  C
pthread_attr_getdetachstate     P  C  P  P  P  P  P  P  P  P  C  C
pthread_attr_getguardsize       P  C  P  P  P  P  -  P  P  P  C  C
pthread_attr_getinheritsched    P  C  P  P  P  P  P  P  P  P  -  -
pthread_attr_getschedparam      P  C  P  P  P  P  P  P  P  P  C  C
pthread_attr_getschedpolicy     P  C  P  P  P  P  P  P  P  P  -  C
pthread_attr_getscope           P  C  P  P  P  P  P  P  P  P  C  C
pthread_attr_getstack           P  C  P  P  P  P  P  P  -  C  -  C
pthread_attr_getstackaddr       P  -  P  P  P  P  P  P  P  P  -  -
pthread_attr_getstacksize       P  C  P  P  P  P  P  P  P  P  C  C
pthread_attr_init               P  C  P  P  P  P  P  P  P  P  C  C
pthread_attr_setdetachstate     P  C  P  P  P  P  P  P  P  P  C  C
pthread_attr_setguardsize       P  C  P  P  P  P  -  P  P  P  C  C
pthread_attr_setinheritsched    P  C  P  P  P  P  P  P  P  P  -  -
pthread_attr_setschedparam      P  C  P  P  P  P  P  P  P  P  C  C
pthread_attr_setschedpolicy     P  C  P  P  P  P  P  P  P  P  -  C
pthread_attr_setscope           P  C  P  P  P  P  P  P  P  P  C  C
pthread_attr_setstack           P  C  P  P  P  P  P  P  -  C  -  C
pthread_attr_setstackaddr       P  -  P  P  P  P  P  P  P  P  -  -
pthread_attr_setstacksize       P  C  P  P  P  P  P  P  P  P  C  C
pthread_barrier_destroy         P  C  P  P  P  P  -  -  -  C  C  C
pthread_barrier_init            P  C  P  P  P  P  -  -  -  C  C  C
pthread_barrier_wait            P  C  P  P  P  P  -  -  -  C  C  C
pthread_barrierattr_destroy     P  C  P  P  P  P  -  -  -  C  C  C
pthread_barrierattr_init        P  C  P  P  P  P  -  -  -  C  C  C
pthread_barrierattr_setpshared  P  C  P  P  P  -  -  -  -  C  C  C
pthread_cancel                  P  C  P  P  P  P  P  P  P  P  C  -
pthread_cond_broadcast          P  C  P  P  P  P  P  P  P  P  C  C
pthread_cond_destroy            P  C  P  P  P  P  P  P  P  P  C  C
pthread_cond_init               P  C  P  P  P  P  P  P  P  P  C  C
pthread_cond_signal             P  C  P  P  P  P  P  P  P  P  C  C
pthread_cond_timedwait          P  C  P  P  P  P  P  P  P  P  C  C
pthread_cond_wait               P  C  P  P  P  P  P  P  P  P  C  C
pthread_condattr_destroy        P  C  P  P  P  P  P  P  P  P  C  C
pthread_condattr_getpshared     P  C  P  P  P  -  -  P  P  P  C  C
pthread_condattr_init           P  C  P  P  P  P  P  P  P  P  C  C
pthread_condattr_setpshared     P  C  P  P  P  -  -  P  P  P  C  C
pthread_create                  P  C  P  P  P  P  P  P  P  P  C  C
pthread_detach                  P  C  P  P  P  P  P  P  P  P  C  C
pthread_equal                   P  C  P  P  P  P  P  P  P  P  C  C
pthread_exit                    P  C  P  P  P  P  P  P  P  P  C  C
pthread_getattr_np              P  C  P  P  -  -  -  -  -  -  -  C
pthread_getconcurrency          P  C  P  P  P  -  P  P  P  P  C  -
pthread_getcpuclockid           P  C  P  P  -  -  -  -  -  -  -  C
pthread_getschedparam           P  C  P  P  P  P  P  P  P  P  C  C
pthread_getspecific             P  C  P  P  P  P  P  P  P  P  C  C
pthread_join                    P  C  P  P  P  P  P  P  P  P  C  C
pthread_key_create              P  C  P  P  P  P  P  P  P  P  C  C
pthread_key_delete              P  C  P  P  P  P  P  P  P  P  C  C
pthread_kill                    P  C  P  P  P  P  P  P  P  P  C  C
pthread_kill_other_threads_np   P  -  -  P  -  -  -  -  -  -  -  -
pthread_mutex_destroy           P  C  P  P  P  P  P  P  P  P  C  C
pthread_mutex_init              P  C  P  P  P  P  P  P  P  P  C  C
pthread_mutex_lock              P  C  P  P  P  P  P  P  P  P  C  C
pthread_mutex_timedlock         P  C  P  P  P  -  -  -  -  C  C  C
pthread_mutex_trylock           P  C  P  P  P  P  P  P  P  P  C  C
pthread_mutex_unlock            P  C  P  P  P  P  P  P  P  P  C  C
pthread_mutexattr_destroy       P  C  P  P  P  P  P  P  P  P  C  C
pthread_mutexattr_getkind_np    P  -  -  P  P  -  P  -  -  -  -  -
pthread_mutexattr_getpshared    P  C  P  P  P  -  -  P  P  P  C  C
pthread_mutexattr_gettype       P  C  P  P  P  P  P  P  P  P  C  C
pthread_mutexattr_init          P  C  P  P  P  P  P  P  P  P  C  C
pthread_mutexattr_setkind_np    P  -  -  P  P  -  P  -  -  -  -  -
pthread_mutexattr_setpshared    P  C  P  P  P  -  -  P  P  P  C  C
pthread_mutexattr_settype       P  C  P  P  P  P  P  P  P  P  C  C
pthread_once                    P  C  P  P  P  P  P  P  P  P  C  C
pthread_rwlock_destroy          P  C  P  P  P  P  P  P  P  P  C  C
pthread_rwlock_init             P  C  P  P  P  P  P  P  P  P  C  C
pthread_rwlock_rdlock           P  C  P  P  P  P  P  P  P  P  C  C
pthread_rwlock_timedrdlock      P  C  P  P  P  P  -  -  -  C  C  C
pthread_rwlock_timedwrlock      P  C  P  P  P  P  -  -  -  C  C  C
pthread_rwlock_tryrdlock        P  C  P  P  P  P  P  P  P  P  C  C
pthread_rwlock_trywrlock        P  C  P  P  P  P  P  P  P  P  C  C
pthread_rwlock_unlock           P  C  P  P  P  P  P  P  P  P  C  C
pthread_rwlock_wrlock           P  C  P  P  P  P  P  P  P  P  C  C
pthread_rwlockattr_destroy      P  C  P  P  P  P  P  P  P  P  C  C
pthread_rwlockattr_getkind_np   P  -  -  P  -  -  -  -  -  -  -  C
pthread_rwlockattr_getpshared   P  C  P  P  P  -  P  P  P  P  C  C
pthread_rwlockattr_init         P  C  P  P  P  P  P  P  P  P  C  C
pthread_rwlockattr_setkind_np   P  -  -  P  -  -  -  -  -  -  -  C
pthread_rwlockattr_setpshared   P  C  P  P  P  -  P  P  P  P  C  C
pthread_self                    P  C  P  P  P  P  P  P  P  P  C  C
pthread_setcancelstate          P  C  P  P  P  P  P  P  P  P  C  -
pthread_setcanceltype           P  C  P  P  P  P  P  P  P  P  C  -
pthread_setconcurrency          P  C  P  P  P  -  P  P  P  P  C  -
pthread_setschedparam           P  C  P  P  P  P  P  P  P  P  C  C
pthread_setspecific             P  C  P  P  P  P  P  P  P  P  C  C
pthread_sigmask                 P  C  P  P  P  P  P  P  P  P  C  C
pthread_spin_destroy            P  C  P  P  P  P  -  -  -  C  C  C
pthread_spin_init               P  C  P  P  P  P  -  -  -  C  C  C
pthread_spin_lock               P  C  P  P  P  P  -  -  -  C  C  C
pthread_spin_trylock            P  C  P  P  P  P  -  -  -  C  C  C
pthread_spin_unlock             P  C  P  P  P  P  -  -  -  C  C  C
pthread_testcancel              P  C  P  P  P  P  P  P  P  P  C  -
pthread_yield                   P  -  P  P  P  -  P  P  -  -  -  -

I created this table using the attached data files (results of 'nm'
with a bit of post-processing) and this script:

for sym in `grep ^pthread_ glibc-2.3.6/libpthread`; do
  pat="^${sym}\$";
  if grep "$pat" glibc-2.3.6/libpthread >/dev/null; then a=P; else if grep 
"$pat" glibc-2.3.6/libc >/dev/null; then a=C; else a=-; fi; fi;
  if grep "$pat" musl/libc >/dev/null; then b=C; else b=-; fi;
  if grep "$pat" hurd-0.9/libpthread >/dev/null; then c=P; else if grep "$pat" 
hurd-0.9/libc >/dev/null; then c=C; else c=-; fi; fi;
  if grep "$pat" glibc-2.13-kfreebsd/libpthread >/dev/null; then d=P; else if 
grep "$pat" glibc-2.13-kfreebsd/libc >/dev/null; then d=C; else d=-; fi; fi;
  if grep "$pat" freebsd-6.4/libpthread >/dev/null; then e=P; else if grep 
"$pat" freebsd-6.4/libc >/dev/null; then e=C; else e=-; fi; fi;
  if grep "$pat" netbsd-5.0.1/libpthread >/dev/null; then f=P; else if grep 
"$pat" netbsd-5.0.1/libc >/dev/null; then f=C; else f=-; fi; fi;
  if grep "$pat" openbsd-3.8/libpthread >/dev/null; then g=P; else if grep 
"$pat" openbsd-3.8/libc >/dev/null; then g=C; else g=-; fi; fi;
  if grep "$pat" hpux-11.31-ia64/libpthread >/dev/null; then h=P; else if grep 
"$pat" hpux-11.31-ia64/libc >/dev/null; then h=C; else h=-; fi; fi;
  if grep "$pat" irix-6.5/libpthread >/dev/null; then i=P; else if grep "$pat" 
irix-6.5/libc >/dev/null; then i=C; else i=-; fi; fi;
  if grep "$pat" solaris-2.10/libpthread >/dev/null; then j=P; else if grep 
"$pat" solaris-2.10/libc >/dev/null; then j=C; else j=-; fi; fi;
  if grep "$pat" haiku/libroot >/dev/null; then k=C; else k=-; fi;
  if grep "$pat" android-9.0/libc >/dev/null; then l=C; else l=-; fi;
  printf '%-32s%s  %s  %s  %s  %s  %s  %s  %s  %s  %s  %s  %s\n' $sym $a $b $c 
$d $e $f $g $h $i $j $k $l;
done

Now, for the !PTHREAD_IN_USE_DETECTION_HARD case, we need a symbol that is
  - 'P' in the columns A*. C*, D*, E*, F*, G*, H*, I*, J*,
  - not '-' in any column.

Also, we have to eliminate pthread_cancel and pthread_kill, because - as
the comment says - they got added to libc in newer versions of FreeBSD,
a fact that is not visible from the 'nm' results.

Result: 'pthread_cancel' won't do, because of the L* (Android) column - just
like Devin Hussey reported -, but any of the following symbols will do:

pthread_attr_destroy
pthread_attr_getdetachstate
pthread_attr_getschedparam
pthread_attr_getscope
pthread_attr_getstacksize
pthread_attr_init
pthread_attr_setdetachstate
pthread_attr_setschedparam
pthread_attr_setscope
pthread_attr_setstacksize
pthread_cond_broadcast
pthread_cond_destroy
pthread_cond_init
pthread_cond_signal
pthread_cond_timedwait
pthread_cond_wait
pthread_condattr_destroy
pthread_condattr_init
pthread_create
pthread_detach
pthread_equal
pthread_exit
pthread_getschedparam
pthread_getspecific
pthread_join
pthread_key_create
pthread_key_delete
pthread_mutex_destroy
pthread_mutex_init
pthread_mutex_lock
pthread_mutex_trylock
pthread_mutex_unlock
pthread_mutexattr_destroy
pthread_mutexattr_gettype
pthread_mutexattr_init
pthread_mutexattr_settype
pthread_once
pthread_rwlock_destroy
pthread_rwlock_init
pthread_rwlock_rdlock
pthread_rwlock_tryrdlock
pthread_rwlock_trywrlock
pthread_rwlock_unlock
pthread_rwlock_wrlock
pthread_rwlockattr_destroy
pthread_rwlockattr_init
pthread_self
pthread_setschedparam
pthread_setspecific
pthread_sigmask

If FreeBSD continues on their way (adding various implementations from
libpthread to libc), any symbol != pthread_create is a bit risky to use.
So, the best to use is pthread_create on all systems.

The reason I did not do that in the first place on 2018-02-17 was that
I didn't want to break other platforms. But now I have considered all
relevant platforms.

I tested this, and on IRIX 6.5 this change introduces a regression:
test-once1 succeeded before, and now crashes with
./test-once1: rld: Fatal Error: attempted access to unresolvable symbol in 
./test-once1: pthread_once

The reason is that on IRIX, libc defines pthread_create (but not 
pthread_cancel),
so the test (pthread_create != NULL) always evaluates to true.

So, the matrix above was incorrect. We need to consider also whether
a symbol is defined in libc, when it is defined in libpthread.

for sym in `grep ^pthread_ glibc-2.3.6/libpthread`; do
  pat="^${sym}\$";
  if grep "$pat" glibc-2.3.6/libpthread >/dev/null; then ap=P; else ap=-; fi;
  if grep "$pat" glibc-2.3.6/libc >/dev/null; then a=C; else a=-; fi;
  if grep "$pat" musl/libc >/dev/null; then b=C; else b=-; fi;
  if grep "$pat" hurd-0.9/libpthread >/dev/null; then cp=P; else cp=-; fi;
  if grep "$pat" hurd-0.9/libc >/dev/null; then c=C; else c=-; fi;
  if grep "$pat" glibc-2.13-kfreebsd/libpthread >/dev/null; then dp=P; else 
dp=-; fi;
  if grep "$pat" glibc-2.13-kfreebsd/libc >/dev/null; then d=C; else d=-; fi;
  if grep "$pat" freebsd-6.4/libpthread >/dev/null; then e1p=P; else e1p=-; fi;
  if grep "$pat" freebsd-6.4/libc >/dev/null; then e1=C; else e1=-; fi;
  if grep "$pat" freebsd-11.0/libpthread >/dev/null; then e2p=P; else e2p=-; fi;
  if grep "$pat" freebsd-11.0/libc >/dev/null; then e2=C; else e2=-; fi;
  if grep "$pat" netbsd-5.0.1/libpthread >/dev/null; then fp=P; else fp=-; fi;
  if grep "$pat" netbsd-5.0.1/libc >/dev/null; then f=C; else f=-; fi;
  if grep "$pat" openbsd-3.8/libpthread >/dev/null; then gp=P; else gp=-; fi;
  if grep "$pat" openbsd-3.8/libc >/dev/null; then g=C; else g=-; fi;
  if grep "$pat" hpux-11.31-ia64/libpthread >/dev/null; then hp=P; else hp=-; 
fi;
  if grep "$pat" hpux-11.31-ia64/libc >/dev/null; then h=C; else h=-; fi;
  if grep "$pat" irix-6.5/libpthread >/dev/null; then ip=P; else ip=-; fi;
  if grep "$pat" irix-6.5/libc >/dev/null; then i=C; else i=-; fi;
  if grep "$pat" solaris-2.10/libpthread >/dev/null; then jp=P; else jp=-; fi;
  if grep "$pat" solaris-2.10/libc >/dev/null; then j=C; else j=-; fi;
  if grep "$pat" haiku/libroot >/dev/null; then k=C; else k=-; fi;
  if grep "$pat" android-9.0/libc >/dev/null; then l=C; else l=-; fi;
  printf '%-32s%s%s %s  %s%s %s%s %s%s %s%s %s%s %s%s %s%s %s%s %s%s %s  %s\n' 
$sym $ap $a $b $cp $c $dp $d $e1p $e1 $e2p $e2 $fp $f $gp $g $hp $h $ip $i $jp 
$j $k $l;
done

                                A* B* C* D* E1*E2*F* G* H* I* J* K* L*

pthread_atfork                  P- C  P- P- P- PC -C -- PC P- -C C  C
pthread_attr_destroy            PC C  PC PC P- PC P- P- PC PC PC C  C
pthread_attr_getdetachstate     PC C  PC PC P- PC P- P- PC P- PC C  C
pthread_attr_getguardsize       P- C  P- P- P- PC P- -- PC P- PC C  C
pthread_attr_getinheritsched    PC C  PC PC P- PC P- P- PC P- PC -  -
pthread_attr_getschedparam      PC C  PC PC P- PC P- P- PC P- PC C  C
pthread_attr_getschedpolicy     PC C  PC PC P- PC P- P- PC P- PC -  C
pthread_attr_getscope           PC C  PC PC P- PC P- P- PC P- PC C  C
pthread_attr_getstack           P- C  P- P- P- P- P- P- P- -- -C -  C
pthread_attr_getstackaddr       P- -  P- P- P- PC P- P- PC P- PC -  -
pthread_attr_getstacksize       P- C  P- P- P- PC P- P- PC P- PC C  C
pthread_attr_init               PC C  PC PC P- PC P- P- PC PC PC C  C
pthread_attr_setdetachstate     PC C  PC PC P- PC P- P- PC PC PC C  C
pthread_attr_setguardsize       P- C  P- P- P- PC P- -- PC P- PC C  C
pthread_attr_setinheritsched    PC C  PC PC P- PC P- P- PC P- PC -  -
pthread_attr_setschedparam      PC C  PC PC P- PC P- P- PC P- PC C  C
pthread_attr_setschedpolicy     PC C  PC PC P- PC P- P- PC P- PC -  C
pthread_attr_setscope           PC C  PC PC P- PC P- P- PC P- PC C  C
pthread_attr_setstack           P- C  P- P- P- P- P- P- P- -- -C -  C
pthread_attr_setstackaddr       P- -  P- P- P- PC P- P- PC PC PC -  -
pthread_attr_setstacksize       P- C  P- P- P- PC P- P- PC PC PC C  C
pthread_barrier_destroy         P- C  P- P- P- P- P- -- -- -- -C C  C
pthread_barrier_init            P- C  P- P- P- P- P- -- -- -- -C C  C
pthread_barrier_wait            P- C  P- P- P- P- P- -- -- -- -C C  C
pthread_barrierattr_destroy     P- C  P- P- P- P- P- -- -- -- -C C  C
pthread_barrierattr_init        P- C  P- P- P- P- P- -- -- -- -C C  C
pthread_barrierattr_setpshared  P- C  P- P- P- P- -- -- -- -- -C C  C
pthread_cancel                  P- C  P- P- P- PC P- P- PC P- PC C  -
pthread_cond_broadcast          PC C  PC PC PC PC P- P- PC PC PC C  C
pthread_cond_destroy            PC C  PC PC PC PC P- P- PC PC PC C  C
pthread_cond_init               PC C  PC PC PC PC P- P- PC PC PC C  C
pthread_cond_signal             PC C  PC PC PC PC P- P- PC PC PC C  C
pthread_cond_timedwait          PC C  PC PC P- PC P- P- PC PC PC C  C
pthread_cond_wait               PC C  PC PC PC PC P- P- PC PC PC C  C
pthread_condattr_destroy        PC C  PC PC P- P- P- P- PC P- PC C  C
pthread_condattr_getpshared     P- C  P- P- P- P- -- -- PC P- PC C  C
pthread_condattr_init           PC C  PC PC P- P- P- P- PC P- PC C  C
pthread_condattr_setpshared     P- C  P- P- P- P- -- -- PC P- PC C  C
pthread_create                  P- C  P- P- P- P- P- P- PC PC PC C  C
pthread_detach                  P- C  P- P- P- PC P- P- PC P- PC C  C
pthread_equal                   PC C  PC PC P- PC P- P- PC P- PC C  C
pthread_exit                    PC C  PC PC P- PC P- P- PC PC PC C  C
pthread_getattr_np              P- C  P- P- -- -- -- -- -- -- -- -  C
pthread_getconcurrency          P- C  P- P- P- P- -- P- PC P- PC C  -
pthread_getcpuclockid           P- C  P- P- -- P- -- -- -- -- -- -  C
pthread_getschedparam           PC C  PC PC P- P- P- P- PC P- PC C  C
pthread_getspecific             P- C  P- P- PC PC P- P- PC P- PC C  C
pthread_join                    P- C  P- P- P- PC P- P- PC P- PC C  C
pthread_key_create              P- C  P- P- PC PC P- P- PC P- PC C  C
pthread_key_delete              P- C  P- P- PC PC P- P- PC P- PC C  C
pthread_kill                    P- C  P- P- P- PC P- P- PC P- PC C  C
pthread_kill_other_threads_np   P- -  -- P- -- -- -- -- -- -- -- -  -
pthread_mutex_destroy           PC C  PC PC PC PC P- P- PC PC PC C  C
pthread_mutex_init              PC C  PC PC PC PC P- P- PC PC PC C  C
pthread_mutex_lock              PC C  PC PC PC PC P- P- PC PC PC C  C
pthread_mutex_timedlock         P- C  P- P- P- P- -- -- -- -- -C C  C
pthread_mutex_trylock           P- C  P- P- PC PC P- P- PC PC PC C  C
pthread_mutex_unlock            PC C  PC PC PC PC P- P- PC PC PC C  C
pthread_mutexattr_destroy       P- C  P- P- PC PC P- P- PC P- PC C  C
pthread_mutexattr_getkind_np    P- -  -- P- P- P- -- P- -- -- -- -  -
pthread_mutexattr_getpshared    P- C  P- P- P- P- -- -- PC P- PC C  C
pthread_mutexattr_gettype       P- C  P- P- P- P- P- P- PC P- PC C  C
pthread_mutexattr_init          P- C  P- P- PC PC P- P- PC P- PC C  C
pthread_mutexattr_setkind_np    P- -  -- P- P- P- -- P- -- -- -- -  -
pthread_mutexattr_setpshared    P- C  P- P- P- P- -- -- PC P- PC C  C
pthread_mutexattr_settype       P- C  P- P- PC PC P- P- PC P- PC C  C
pthread_once                    P- C  P- P- PC PC P- P- PC P- PC C  C
pthread_rwlock_destroy          P- C  P- P- PC PC P- P- PC P- PC C  C
pthread_rwlock_init             P- C  P- P- PC PC P- P- PC P- PC C  C
pthread_rwlock_rdlock           P- C  P- P- PC PC P- P- PC P- PC C  C
pthread_rwlock_timedrdlock      P- C  P- P- P- P- P- -- -- -- -C C  C
pthread_rwlock_timedwrlock      P- C  P- P- P- P- P- -- -- -- -C C  C
pthread_rwlock_tryrdlock        P- C  P- P- PC PC P- P- PC P- PC C  C
pthread_rwlock_trywrlock        P- C  P- P- PC PC P- P- PC P- PC C  C
pthread_rwlock_unlock           P- C  P- P- PC PC P- P- PC P- PC C  C
pthread_rwlock_wrlock           P- C  P- P- PC PC P- P- PC P- PC C  C
pthread_rwlockattr_destroy      P- C  P- P- P- P- P- P- PC P- PC C  C
pthread_rwlockattr_getkind_np   P- -  -- P- -- -- -- -- -- -- -- -  C
pthread_rwlockattr_getpshared   P- C  P- P- P- P- -- P- PC P- PC C  C
pthread_rwlockattr_init         P- C  P- P- P- P- P- P- PC P- PC C  C
pthread_rwlockattr_setkind_np   P- -  -- P- -- -- -- -- -- -- -- -  C
pthread_rwlockattr_setpshared   P- C  P- P- P- P- -- P- PC P- PC C  C
pthread_self                    PC C  PC PC PC PC P- P- PC PC PC C  C
pthread_setcancelstate          PC C  PC PC P- PC P- P- PC P- PC C  -
pthread_setcanceltype           PC C  PC PC P- PC P- P- PC P- PC C  -
pthread_setconcurrency          P- C  P- P- P- P- -- P- PC P- PC C  -
pthread_setschedparam           PC C  PC PC P- P- P- P- PC P- PC C  C
pthread_setspecific             P- C  P- P- PC PC P- P- PC P- PC C  C
pthread_sigmask                 P- C  P- P- PC PC P- P- PC P- PC C  C
pthread_spin_destroy            P- C  P- P- P- P- P- -- -- -- -C C  C
pthread_spin_init               P- C  P- P- P- P- P- -- -- -- -C C  C
pthread_spin_lock               P- C  P- P- P- P- P- -- -- -- -C C  C
pthread_spin_trylock            P- C  P- P- P- P- P- -- -- -- -C C  C
pthread_spin_unlock             P- C  P- P- P- P- P- -- -- -- -C C  C
pthread_testcancel              P- C  P- P- P- PC P- P- PC PC PC C  -
pthread_yield                   P- -  P- P- P- P- -- P- P- -- -- -  -

Now, for the !PTHREAD_IN_USE_DETECTION_HARD case, we need a symbol that is
  - 'P-' in the columns A*. C*, D*, E1*, E2*, F*, G*, H*, I*, J*,
  - not '-' or '--' in any column.

But this has no solution, not even 'pthread_cancel'. So apparently
'PC' needs to be allowed in the columns H* and J* ... The result is
this list of symbols:

pthread_mutexattr_gettype
pthread_rwlockattr_destroy
pthread_rwlockattr_init

I've tested this on all platforms listed above, except Android. I'm
pretty sure it works on Android as well.


2018-05-10  Bruno Haible  <address@hidden>

        lock, cond, thread, tls: Use a different symbol as libpthread witness.
        Reported by Devin Hussey <address@hidden>.
        Based on a patch by Paul Eggert.
        * lib/glthread/lock.h (pthread_in_use): Use 'pthread_mutexattr_gettype'
        as witness of libpthread.
        * lib/glthread/cond.h (pthread_in_use): Likewise.
        * lib/glthread/thread.h (pthread_in_use): Likewise.
        * lib/glthread/tls.h (pthread_in_use): Likewise.

diff --git a/lib/glthread/cond.h b/lib/glthread/cond.h
index 54040ff..32a5f03 100644
--- a/lib/glthread/cond.h
+++ b/lib/glthread/cond.h
@@ -114,8 +114,8 @@ extern int glthread_in_use (void);
 #  endif
 
 #  if !PTHREAD_IN_USE_DETECTION_HARD
-#   pragma weak pthread_cancel
-#   define pthread_in_use() (pthread_cancel != NULL)
+#   pragma weak pthread_mutexattr_gettype
+#   define pthread_in_use() (pthread_mutexattr_gettype != NULL)
 #  endif
 
 # else
diff --git a/lib/glthread/lock.h b/lib/glthread/lock.h
index dd8e1f8..c4251c3 100644
--- a/lib/glthread/lock.h
+++ b/lib/glthread/lock.h
@@ -149,18 +149,14 @@ extern int glthread_in_use (void);
 #  endif
 
 #  if !PTHREAD_IN_USE_DETECTION_HARD
-    /* On most platforms, pthread_cancel or pthread_kill can be used to
-       determine whether libpthread is in use.
-       On newer versions of FreeBSD, however, this is no longer possible,
-       because pthread_cancel and pthread_kill got added to libc.  Therefore
-       use pthread_create to test whether libpthread is in use.  */
-#   if defined __FreeBSD__ || defined __DragonFly__ /* FreeBSD */
-#    pragma weak pthread_create
-#    define pthread_in_use() (pthread_create != NULL)
-#   else /* glibc, NetBSD, OpenBSD, IRIX, OSF/1, Solaris */
-#    pragma weak pthread_cancel
-#    define pthread_in_use() (pthread_cancel != NULL)
-#   endif
+    /* Considering all platforms with USE_POSIX_THREADS_WEAK, only few symbols
+       can be used to determine whether libpthread is in use.  These are:
+         pthread_mutexattr_gettype
+         pthread_rwlockattr_destroy
+         pthread_rwlockattr_init
+     */
+#   pragma weak pthread_mutexattr_gettype
+#   define pthread_in_use() (pthread_mutexattr_gettype != NULL)
 #  endif
 
 # else
diff --git a/lib/glthread/thread.h b/lib/glthread/thread.h
index d8098c4..39a71de 100644
--- a/lib/glthread/thread.h
+++ b/lib/glthread/thread.h
@@ -149,8 +149,8 @@ extern int glthread_in_use (void);
 #  endif
 
 #  if !PTHREAD_IN_USE_DETECTION_HARD
-#   pragma weak pthread_cancel
-#   define pthread_in_use() (pthread_cancel != NULL)
+#   pragma weak pthread_mutexattr_gettype
+#   define pthread_in_use() (pthread_mutexattr_gettype != NULL)
 #  endif
 
 # else
diff --git a/lib/glthread/tls.h b/lib/glthread/tls.h
index 12bf6d5..af1fb3b 100644
--- a/lib/glthread/tls.h
+++ b/lib/glthread/tls.h
@@ -76,8 +76,8 @@ extern int glthread_in_use (void);
 #  endif
 
 #  if !PTHREAD_IN_USE_DETECTION_HARD
-#   pragma weak pthread_cancel
-#   define pthread_in_use() (pthread_cancel != NULL)
+#   pragma weak pthread_mutexattr_gettype
+#   define pthread_in_use() (pthread_mutexattr_gettype != NULL)
 #  endif
 
 # else

Attachment: symlists.tar.gz
Description: application/compressed-tar


reply via email to

[Prev in Thread] Current Thread [Next in Thread]