/[svn]/linuxsampler/trunk/m4/nptl_bug.m4
ViewVC logotype

Contents of /linuxsampler/trunk/m4/nptl_bug.m4

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1472 - (show annotations) (download)
Mon Nov 5 15:19:42 2007 UTC (12 years, 5 months ago) by schoenebeck
File size: 2874 byte(s)
- let the NPTL bug check always succeed on Windows
  as this is only a Linux issue

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. On Windows systems this test always succeeds.
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 <stdlib.h>
27
28 #if WIN32
29
30 int main() {
31 exit(0);
32 }
33
34 #else /* POSIX system */
35
36 #include <stdio.h>
37 #include <pthread.h>
38 #include <unistd.h>
39
40 pthread_attr_t __thread_attr;
41 pthread_t __thread_id;
42
43 pthread_mutex_t __posix_mutex;
44 pthread_mutexattr_t __posix_mutexattr;
45
46 /// entry point for the spawned thread
47 void* __pthread_launcher(void* p) {
48 // let the thread be killable under any circumstances
49 // (without this function call, this test always succeeds !)
50 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
51
52 // this will block this 2nd thread, since we already
53 // locked this mutex by the main thread
54 pthread_mutex_lock(&__posix_mutex);
55
56 // here we would access shared resources, etc.
57
58 // just pro forma, the remainder of this function is actually not of
59 // interest, since this thread is always terminated at its mutex lock call
60 pthread_mutex_unlock(&__posix_mutex);
61 return NULL;
62 }
63
64 int main() {
65
66 // initialize mutex and thread attribute
67 pthread_mutexattr_init(&__posix_mutexattr);
68 pthread_mutex_init(&__posix_mutex, &__posix_mutexattr);
69 pthread_attr_init(&__thread_attr);
70
71 // already lock the mutex by the main thread ...
72 pthread_mutex_lock(&__posix_mutex);
73
74 int res;
75
76 // create and run a 2nd thread
77 res = pthread_create(&__thread_id, &__thread_attr, __pthread_launcher, NULL);
78 if (res) {
79 exit(-1);
80 }
81
82 // give the other thread a chance to spawn
83 usleep(400000);
84
85 // kill the other thread
86 pthread_cancel(__thread_id);
87 pthread_detach(__thread_id);
88
89 // give the other thread a chance to finish its execution
90 usleep(400000);
91
92 // cleanup
93 // (just pro forma, doesnt actually matter for this test case)
94 pthread_attr_destroy(&__thread_attr);
95 pthread_mutex_destroy(&__posix_mutex);
96 pthread_mutexattr_destroy(&__posix_mutexattr);
97
98 exit(0);
99 }
100 #endif /* WIN32 */
101
102 ],[
103 AC_MSG_RESULT(no)
104 ifelse([$2], , :, [$2])
105 ], [
106 AC_MSG_RESULT(yes)
107 ifelse([$1], , :, [$1])
108 ], [
109 AC_MSG_RESULT(disabled)
110 ifelse([$2], , :, [$2])
111 ])
112
113 AC_LANG_RESTORE
114 ])

  ViewVC Help
Powered by ViewVC