/* * From at opengroup.org pthread_rwlock_unlock[1]: * * If an implementation detects that the value specified by the rwlock argument * to pthread_rwlock_unlock() refers to a read-write lock object for which the * current thread does not hold a lock, it is recommended that the function * should fail and report an [EPERM] error. * * EPERM used to be a specified return value prior to Issue 7: * The [EPERM] error for a read-write lock object for which the current thread * does not hold a lock is removed; this condition results in undefined * behavior. * * [1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_rwlock_unlock.html * * cc -pthread -o rwlock rwlock.c && ./rwlock */ #include #include #include pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER; #define CHECK(x) do { \ int e, r; \ char buf[256]; \ printf("invoking %s\n", #x); \ r = x; \ e = errno; \ strerror_r(r, buf, sizeof(buf)); \ printf("%s returned %d (%s)\n", #x, r, buf); \ if (r != 0) { \ strerror_r(e, buf, sizeof(buf)); \ printf("errno %d (%s)\n", e, buf); \ } \ } while(0) void * unlock(void *arg) { CHECK(pthread_rwlock_unlock(&rwlock)); } int main(int argc, char **argv) { int rc=0; pthread_t td; printf("Enter Testcase - %s\n", argv[0]); CHECK(pthread_rwlock_wrlock(&rwlock)); CHECK(pthread_create(&td, NULL, unlock, NULL)); CHECK(pthread_join(td, NULL)); return 0; }