string test alignment fix by Mahesh Bodapati
[libc-test.git] / src / regression / pthread_rwlock-ebusy.c
blob9f157a80851473b9952f8bb1811381933f78daeb
1 // commit: e5dd18319bbd47c89aac5e1571771958a43e067d 2011-03-08
2 // pthread_rwlock_try* should fail with EBUSY
3 #include <pthread.h>
4 #include <errno.h>
5 #include <string.h>
6 #include "test.h"
8 #define T(f) if ((r=(f))) t_error(#f " failed: %s\n", strerror(r))
10 static void *tryrdlock(void *arg)
12 int r = pthread_rwlock_tryrdlock(arg);
13 if (r != EBUSY)
14 t_error("tryrdlock for wrlocked lock returned %s, want EBUSY\n", strerror(r));
15 return 0;
18 static void *trywrlock(void *arg)
20 int r = pthread_rwlock_trywrlock(arg);
21 if (r != EBUSY)
22 t_error("trywrlock for rdlocked lock returned %s, want EBUSY\n", strerror(r));
23 return 0;
26 int main(void)
28 pthread_t t;
29 pthread_rwlock_t rw = PTHREAD_RWLOCK_INITIALIZER;
30 void *p;
31 int r;
33 T(pthread_rwlock_rdlock(&rw));
34 T(pthread_create(&t, 0, trywrlock, &rw));
35 T(pthread_join(t, &p));
36 T(pthread_rwlock_unlock(&rw));
38 T(pthread_rwlock_wrlock(&rw));
39 T(pthread_create(&t, 0, tryrdlock, &rw));
40 T(pthread_join(t, &p));
41 T(pthread_rwlock_unlock(&rw));
43 return t_status;