[LTP] [PATCH v2 2/2] open_posix: pthread_rwlock_rdlock: Add GLIBC workaround

Ricardo B. Marlière rbm@suse.com
Mon Sep 22 12:49:06 CEST 2025


From: Ricardo B. Marlière <rbm@suse.com>

GNU/Linux does not support the POSIX standard with regards to the second
assertion of this test. Work around it by making use of the non-portable
flag PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP.

Link: https://sourceware.org/bugzilla/show_bug.cgi?id=13701
Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
---
 .../conformance/interfaces/pthread_rwlock_rdlock/2-1.c            | 8 +++++++-
 .../conformance/interfaces/pthread_rwlock_rdlock/2-2.c            | 8 +++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-1.c
index fa57e64985ef46da143d3f323bb3c727eeb3db66..3b27a0bbbbdfaadf37fa94e129a937cdd9e986db 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-1.c
@@ -144,13 +144,19 @@ int main(void)
 	int cnt = 0;
 	pthread_t rd_thread, wr_thread;
 	int priority;
+	pthread_rwlockattr_t attr;
+
+	pthread_rwlockattr_init(&attr);
+#ifdef __GNUC__
+	pthread_rwlockattr_setkind_np(&attr, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
+#endif
 
 	/* main thread needs to have the highest priority */
 	priority = sched_get_priority_min(TRD_POLICY) + 2;
 	set_priority(pthread_self(), TRD_POLICY, priority);
 	printf("main: has priority: %d\n", priority);
 
-	if (pthread_rwlock_init(&rwlock, NULL) != 0) {
+	if (pthread_rwlock_init(&rwlock, &attr) != 0) {
 		printf("main: Error at pthread_rwlock_init()\n");
 		return PTS_UNRESOLVED;
 	}
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-2.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-2.c
index f6ffddfbe417a7affdf1114b9cc2e97bc09f8fac..4799b1e885caab509fd31173c34ae89beace68e6 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-2.c
@@ -144,12 +144,18 @@ int main(void)
 	int cnt = 0;
 	pthread_t rd_thread, wr_thread;
 	int priority;
+	pthread_rwlockattr_t attr;
+
+	pthread_rwlockattr_init(&attr);
+#ifdef __GNUC__
+	pthread_rwlockattr_setkind_np(&attr, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
+#endif
 
 	/* main thread needs to have the highest priority */
 	priority = sched_get_priority_min(TRD_POLICY) + 2;
 	set_priority(pthread_self(), TRD_POLICY, priority);
 
-	if (pthread_rwlock_init(&rwlock, NULL) != 0) {
+	if (pthread_rwlock_init(&rwlock, &attr) != 0) {
 		printf("main: Error at pthread_rwlock_init()\n");
 		return PTS_UNRESOLVED;
 	}

-- 
2.51.0



More information about the ltp mailing list