[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: lock: more tests
From: |
Bruno Haible |
Subject: |
Re: lock: more tests |
Date: |
Sat, 17 Feb 2018 10:25:30 +0100 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-112-generic; KDE/5.18.0; x86_64; ; ) |
The new test-once1 test crashes on FreeBSD 11, through abort().
This is because newer versions of FreeBSD now have pthread_cancel
in libc (older versions had it only in libthread, libthr), thus
the macro pthread_in_use() produces the value 1, but pthread_once()
returns ENOSYS. (Cf.
https://github.com/freebsd/freebsd/blob/master/lib/libc/gen/_pthread_stubs.c )
This fixes it.
I considered adding an autoconf test for the presence of pthread_cancel
versus pthread_create in libc vs. libpthread (rather than a #ifdef __FreeBSD__).
But we want binaries built with older versions of FreeBSD to work with newer
versions of FreeBSD as well; an autoconf test cannot do this.
2018-02-17 Bruno Haible <address@hidden>
lock: Fix test-once1 crash on FreeBSD11.
* lib/glthread/lock.h: On FreeBSD, test the weak value of the symbol
'pthread_create', not 'pthread_cancel'.
diff --git a/lib/glthread/lock.h b/lib/glthread/lock.h
index 87d9df1..dd8e1f8 100644
--- a/lib/glthread/lock.h
+++ b/lib/glthread/lock.h
@@ -149,8 +149,18 @@ extern int glthread_in_use (void);
# endif
# if !PTHREAD_IN_USE_DETECTION_HARD
-# pragma weak pthread_cancel
-# define pthread_in_use() (pthread_cancel != NULL)
+ /* 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
# endif
# else
- lock: more tests, Bruno Haible, 2018/02/17
- Re: lock: more tests,
Bruno Haible <=