diff options
Diffstat (limited to 'nptl')
-rw-r--r-- | nptl/ChangeLog | 2 | ||||
-rw-r--r-- | nptl/tst-mutex3.c | 51 |
2 files changed, 51 insertions, 2 deletions
diff --git a/nptl/ChangeLog b/nptl/ChangeLog index de93173969..1dc5f231bb 100644 --- a/nptl/ChangeLog +++ b/nptl/ChangeLog @@ -1,5 +1,7 @@ 2003-02-15 Ulrich Drepper <drepper@redhat.com> + * tst-mutex3.c (do_test): Add tests for trylock with RECURSIVE mutexes. + * sysdeps/unix/sysv/linux/pthread_kill.c (__pthread_kill): Don't use INLINE_SYSCALL. Error number is returned, not -1. diff --git a/nptl/tst-mutex3.c b/nptl/tst-mutex3.c index c6c75ca0aa..c45637b5cf 100644 --- a/nptl/tst-mutex3.c +++ b/nptl/tst-mutex3.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2002 Free Software Foundation, Inc. +/* Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. @@ -20,12 +20,34 @@ #include <errno.h> #include <pthread.h> #include <stdio.h> +#include <stdlib.h> + + +static pthread_mutex_t m; + + +static void * +tf (void *arg) +{ + int e = pthread_mutex_trylock (&m); + if (e == 0) + { + puts ("mutex_trylock in second thread succeeded"); + exit (1); + } + if (e != EBUSY) + { + puts ("mutex_trylock returned wrong value"); + exit (1); + } + + return NULL; +} static int do_test (void) { - pthread_mutex_t m; pthread_mutexattr_t a; if (pthread_mutexattr_init (&a) != 0) @@ -58,6 +80,12 @@ do_test (void) return 1; } + if (pthread_mutex_trylock (&m) != 0) + { + puts ("1st trylock failed"); + return 1; + } + if (pthread_mutex_unlock (&m) != 0) { puts ("mutex_unlock failed"); @@ -70,6 +98,25 @@ do_test (void) return 1; } + pthread_t th; + if (pthread_create (&th, NULL, tf, NULL) != 0) + { + puts ("create failed"); + return 1; + } + + if (pthread_join (th, NULL) != 0) + { + puts ("join failed"); + return 1; + } + + if (pthread_mutex_unlock (&m) != 0) + { + puts ("3rd mutex_unlock failed"); + return 1; + } + if (pthread_mutex_destroy (&m) != 0) { puts ("mutex_destroy failed"); |