1 |
dnl Christian Schoenebeck 2007-10-18 |
2 |
dnl -------------------------------------------------------------------------- |
3 |
dnl |
4 |
dnl Synopsis: |
5 |
dnl |
6 |
dnl ACX_NPTL_GLIBC_BUG([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]) |
7 |
dnl |
8 |
dnl Check for NPTL glibc bug which caused crashs on Gentoo systems, see |
9 |
dnl Gentoo bug report #194076 for details. This test is ignored on cross- |
10 |
dnl compilations. |
11 |
dnl |
12 |
dnl Note: this test requires LIBS, CFLAGS and CC already been set, i.e. by |
13 |
dnl using ACX_PTHREAD before calling this macro. |
14 |
dnl |
15 |
dnl -------------------------------------------------------------------------- |
16 |
AC_DEFUN([ACX_NPTL_GLIBC_BUG], |
17 |
[ |
18 |
|
19 |
AC_MSG_CHECKING(for NPTL bug) |
20 |
|
21 |
AC_LANG_SAVE |
22 |
AC_LANG_C |
23 |
|
24 |
AC_TRY_RUN([ |
25 |
|
26 |
#include <stdio.h> |
27 |
#include <stdlib.h> |
28 |
#include <pthread.h> |
29 |
#include <unistd.h> |
30 |
|
31 |
pthread_attr_t __thread_attr; |
32 |
pthread_t __thread_id; |
33 |
|
34 |
pthread_mutex_t __posix_mutex; |
35 |
pthread_mutexattr_t __posix_mutexattr; |
36 |
|
37 |
/// entry point for the spawned thread |
38 |
void* __pthread_launcher(void* p) { |
39 |
// let the thread be killable under any circumstances |
40 |
// (without this function call, this test always succeeds !) |
41 |
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); |
42 |
|
43 |
// this will block this 2nd thread, since we already |
44 |
// locked this mutex by the main thread |
45 |
pthread_mutex_lock(&__posix_mutex); |
46 |
|
47 |
// here we would access shared resources, etc. |
48 |
|
49 |
// just pro forma, the remainder of this function is actually not of |
50 |
// interest, since this thread is always terminated at its mutex lock call |
51 |
pthread_mutex_unlock(&__posix_mutex); |
52 |
return NULL; |
53 |
} |
54 |
|
55 |
int main() { |
56 |
|
57 |
// initialize mutex and thread attribute |
58 |
pthread_mutexattr_init(&__posix_mutexattr); |
59 |
pthread_mutex_init(&__posix_mutex, &__posix_mutexattr); |
60 |
pthread_attr_init(&__thread_attr); |
61 |
|
62 |
// already lock the mutex by the main thread ... |
63 |
pthread_mutex_lock(&__posix_mutex); |
64 |
|
65 |
int res; |
66 |
|
67 |
// create and run a 2nd thread |
68 |
res = pthread_create(&__thread_id, &__thread_attr, __pthread_launcher, NULL); |
69 |
if (res) { |
70 |
exit(-1); |
71 |
} |
72 |
|
73 |
// give the other thread a chance to spawn |
74 |
usleep(400000); |
75 |
|
76 |
// kill the other thread |
77 |
pthread_cancel(__thread_id); |
78 |
pthread_detach(__thread_id); |
79 |
|
80 |
// give the other thread a chance to finish its execution |
81 |
usleep(400000); |
82 |
|
83 |
// cleanup |
84 |
// (just pro forma, doesnt actually matter for this test case) |
85 |
pthread_attr_destroy(&__thread_attr); |
86 |
pthread_mutex_destroy(&__posix_mutex); |
87 |
pthread_mutexattr_destroy(&__posix_mutexattr); |
88 |
|
89 |
exit(0); |
90 |
} |
91 |
|
92 |
],[ |
93 |
AC_MSG_RESULT(no) |
94 |
ifelse([$2], , :, [$2]) |
95 |
], [ |
96 |
AC_MSG_RESULT(yes) |
97 |
ifelse([$1], , :, [$1]) |
98 |
], [ |
99 |
AC_MSG_RESULT(disabled) |
100 |
ifelse([$2], , :, [$2]) |
101 |
]) |
102 |
|
103 |
AC_LANG_RESTORE |
104 |
]) |