diff --git a/src/regression/pthread_create-oom.c b/src/regression/pthread_create-oom.c index 56993ec..e8d8169 100644 --- a/src/regression/pthread_create-oom.c +++ b/src/regression/pthread_create-oom.c @@ -1,7 +1,6 @@ // commit: 59666802fba592a59f2f4ea4dcb053287fd55826 2011-02-15 // pthread_create should return EAGAIN on failure #include -#include #include #include #include "test.h" diff --git a/src/regression/pthread_rwlock-ebusy.c b/src/regression/pthread_rwlock-ebusy.c new file mode 100644 index 0000000..c2bc2d7 --- /dev/null +++ b/src/regression/pthread_rwlock-ebusy.c @@ -0,0 +1,44 @@ +// commit: e5dd18319bbd47c89aac5e1571771958a43e067d 2011-03-08 +// pthread_rwlock_try* should fail with EBUSY +#include +#include +#include +#include "test.h" + +#define T(f) if ((r=(f))) t_error(#f " failed: %s\n", strerror(r)) + +static void *tryrdlock(void *arg) +{ + int r = pthread_rwlock_tryrdlock(arg); + if (r != EBUSY) + t_error("tryrdlock for wrlocked lock returned %s, want EBUSY\n", strerror(errno)); + return 0; +} + +static void *trywrlock(void *arg) +{ + int r = pthread_rwlock_trywrlock(arg); + if (r != EBUSY) + t_error("trywrlock for rdlocked lock returned %s, want EBUSY\n", strerror(errno)); + return 0; +} + +int main(void) +{ + pthread_t t; + pthread_rwlock_t rw = PTHREAD_RWLOCK_INITIALIZER; + void *p; + int r; + + T(pthread_rwlock_rdlock(&rw)); + T(pthread_create(&t, 0, trywrlock, &rw)); + T(pthread_join(t, &p)); + T(pthread_rwlock_unlock(&rw)); + + T(pthread_rwlock_wrlock(&rw)); + T(pthread_create(&t, 0, tryrdlock, &rw)); + T(pthread_join(t, &p)); + T(pthread_rwlock_unlock(&rw)); + + return t_status; +}