1 /* Copyright (C) 2002-2013 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
26 static pthread_mutex_t m1
= PTHREAD_MUTEX_INITIALIZER
;
27 static pthread_mutex_t m2
= PTHREAD_MUTEX_INITIALIZER
;
35 if (arg
!= (void *) 42l)
45 /* Ignore all signals. This must not have any effect on delivering
46 the cancellation signal. */
51 if (pthread_sigmask (SIG_BLOCK
, &ss
, NULL
) != 0)
53 puts ("pthread_sigmask failed");
57 pthread_cleanup_push (cleanup
, (void *) 42l);
59 int err
= pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS
, NULL
);
62 printf ("setcanceltype failed: %s\n", strerror (err
));
65 /* The following code is not standard compliant: the mutex functions
66 must not be called with asynchronous cancellation enabled. */
68 err
= pthread_mutex_unlock (&m2
);
71 printf ("child: mutex_unlock failed: %s\n", strerror (err
));
75 err
= pthread_mutex_lock (&m1
);
78 printf ("child: 1st mutex_lock failed: %s\n", strerror (err
));
82 /* We should never come here. */
84 pthread_cleanup_pop (0);
98 /* Get the mutexes. */
99 err
= pthread_mutex_lock (&m1
);
102 printf ("parent: 1st mutex_lock failed: %s\n", strerror (err
));
105 err
= pthread_mutex_lock (&m2
);
108 printf ("parent: 2nd mutex_lock failed: %s\n", strerror (err
));
112 err
= pthread_create (&th
, NULL
, tf
, NULL
);
115 printf ("create failed: %s\n", strerror (err
));
119 err
= pthread_mutex_lock (&m2
);
122 printf ("parent: 3rd mutex_lock failed: %s\n", strerror (err
));
126 err
= pthread_cancel (th
);
129 printf ("cancel failed: %s\n", strerror (err
));
133 err
= pthread_join (th
, &retval
);
136 printf ("join failed: %s\n", strerror (err
));
140 if (retval
!= PTHREAD_CANCELED
)
142 printf ("wrong return value: %p\n", retval
);
148 puts ("cleanup handler called with wrong argument");
153 puts ("cleanup handling not called");
161 #define TEST_FUNCTION do_test ()
162 #include "../test-skeleton.c"