open_posix: Update pthread_rwlock_rdlock 2nd assertion
PATCH 1/1 open_posix: Update pthread_rwlock_rdlock 2nd assertion
From: Ricardo B. Marlière <[email protected]>
The pthread_rwlock_rdlock/2-*.c tests are broken because they rely on an old version of the POSIX standard which says:
If the Thread Execution Scheduling option is supported, and the threads involved in the lock are executing with the scheduling policies SCHED_FIFO or SCHED_RR, the calling thread shall not acquire the lock if a writer holds the lock or if writers of higher or equal priority are blocked on the lock; otherwise, the calling thread shall acquire the lock.
Whereas the new version says:
If the Thread Execution Scheduling option is supported, and the threads that hold or are blocked on the lock are executing with the scheduling policies SCHED_FIFO or SCHED_RR, the calling thread shall not acquire the lock if a writer holds the lock or if the calling thread does not already hold a read lock and writers of higher or equal priority are blocked on the lock; otherwise, the calling thread shall acquire the lock.
This behaviour is not supported by default on GNU/Linux, so add a call to Glibc pthread_rwlockattr_setkind_np() to set the correct lock kind as a prerequisite to the 2-1.c and 2-2.c tests.
--- .../interfaces/pthread_rwlock_rdlock/2-1.c | 21 ++++++++++++++------- .../interfaces/pthread_rwlock_rdlock/2-2.c | 21 ++++++++++++++------- .../interfaces/pthread_rwlock_rdlock/2-3.c | 13 +++++++------ .../interfaces/pthread_rwlock_rdlock/assertions.xml | 15 ++++++++------- 4 files changed, 43 insertions(+), 27 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-1.c +14 -7
@@ -6,12 +6,13 @@* Test that pthread_rwlock_rdlock(pthread_rwlock_t *rwlock) * -* If the Thread Execution Scheduling option is supported, -* and the threads involved in the lock are executing with the -* scheduling policies SCHED_FIFO or SCHED_RR, the calling thread shall not -* acquire the lock if a writer holds the lock or if writers of -* higher or equal priority are blocked on the lock; -* otherwise, the calling thread shall acquire the lock. +* If the Thread Execution Scheduling option is supported, +* and the threads that hold or are blocked on the lock are +* executing with the scheduling policies SCHED_FIFO or SCHED_RR, +* the calling thread shall not acquire the lock if a writer +* holds the lock or if the calling thread does not already hold +* a read lock and writers of higher or equal priority are blocked +* on the lock; otherwise, the calling thread shall acquire the lock. * * In this case, we test "higher priority writer block" *
@@ -143,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 ; }
testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-2.c +14 -7
@@ -6,12 +6,13 @@* Test that pthread_rwlock_rdlock(pthread_rwlock_t *rwlock) * -* If the Thread Execution Scheduling option is supported, -* and the threads involved in the lock are executing with the -* scheduling policies SCHED_FIFO or SCHED_RR, the calling thread shall not -* acquire the lock if a writer holds the lock or if writers of -* higher or equal priority are blocked on the lock; -* otherwise, the calling thread shall acquire the lock. +* If the Thread Execution Scheduling option is supported, +* and the threads that hold or are blocked on the lock are +* executing with the scheduling policies SCHED_FIFO or SCHED_RR, +* the calling thread shall not acquire the lock if a writer +* holds the lock or if the calling thread does not already hold +* a read lock and writers of higher or equal priority are blocked +* on the lock; otherwise, the calling thread shall acquire the lock. * * In this case, we test "equal priority writer block" *
@@ -143,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 ; }
testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-3.c +7 -6
@@ -6,12 +6,13 @@* Test that pthread_rwlock_rdlock(pthread_rwlock_t *rwlock) * -* If the Thread Execution Scheduling option is supported, -* and the threads involved in the lock are executing with the -* scheduling policies SCHED_FIFO or SCHED_RR, the calling thread shall not -* acquire the lock if a writer holds the lock or if writers of -* higher or equal priority are blocked on the lock; -* otherwise, the calling thread shall acquire the lock. +* If the Thread Execution Scheduling option is supported, +* and the threads that hold or are blocked on the lock are +* executing with the scheduling policies SCHED_FIFO or SCHED_RR, +* the calling thread shall not acquire the lock if a writer +* holds the lock or if the calling thread does not already hold +* a read lock and writers of higher or equal priority are blocked +* on the lock; otherwise, the calling thread shall acquire the lock. * * In this case, reader has higher priority than the writer *
testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/assertions.xml +8 -7
@@ -6,13 +6,14 @@ no writers blocked on the lock. </assertion> - <assertion id="2" tag="ref:XSH6:34768:34771"> - If the Thread Execution Scheduling option is supported, - and the threads involved in the lock are executing with the - scheduling policies SCHED_FIFO or SCHED_RR, the calling thread shall not - acquire the lock if a writer holds the lock or if writers of - higher or equal priority are blocked on the lock; - otherwise, the calling thread shall acquire the lock. + <assertion id="2" tag="ref:XSH8:{System Interfaces:pthread_rwlock_rdlock:DESCRIPTION}"> + If the Thread Execution Scheduling option is supported, + and the threads that hold or are blocked on the lock are + executing with the scheduling policies SCHED_FIFO or SCHED_RR, + the calling thread shall not acquire the lock if a writer + holds the lock or if the calling thread does not already hold + a read lock and writers of higher or equal priority are blocked + on the lock; otherwise, the calling thread shall acquire the lock. </assertion> <assertion id="3" tag="ref:XSH6:34772:34775">
---
base-commit: c9e5b1e50889adec8c2bb38ea5fd69cd48edb8b7
change-id: 20250520-fixes-pthread_rwlock_rdlock-b2b8e427160a
Best regards,
Signature · 5 lines
Ricardo B. Marlière <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 28 lines · Ricardo B. Marlière
From: Ricardo B. Marlière <[email protected]>
The pthread_rwlock_rdlock/2-*.c tests are broken because they rely on an old version of the POSIX standard which says:
If the Thread Execution Scheduling option is supported, and the threads involved in the lock are executing with the scheduling policies
SCHED_FIFOorSCHED_RR, the calling thread shall not acquire the lock if a writer holds the lock or if writers of higher or equal priority are blocked on the lock; otherwise, the calling thread shall acquire the lock.Whereas the new version says:
If the Thread Execution Scheduling option is supported, and the threads that hold or are blocked on the lock are executing with the scheduling policies
SCHED_FIFOorSCHED_RR, the calling thread shall not acquire the lock if a writer holds the lock or if the calling thread does not already hold a read lock and writers of higher or equal priority are blocked on the lock; otherwise, the calling thread shall acquire the lock.This behaviour is not supported by default on GNU/Linux, so add a call to Glibc
pthread_rwlockattr_setkind_np()to set the correct lock kind as a prerequisite to the 2-1.c and 2-2.c tests.
Quoted 7 lines
--- .../interfaces/pthread_rwlock_rdlock/2-1.c | 21 ++++++++++++++------- .../interfaces/pthread_rwlock_rdlock/2-2.c | 21 ++++++++++++++------- .../interfaces/pthread_rwlock_rdlock/2-3.c | 13 +++++++------ .../interfaces/pthread_rwlock_rdlock/assertions.xml | 15 ++++++++------- 4 files changed, 43 insertions(+), 27 deletions(-)
Hi Cyril,
I think this one might be worth including in the new release!
Thanks,
- Ricardo.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 10 lines
The pthread_rwlock_rdlock/2-*.c tests are broken because they rely on an old version of the POSIX standard which says:
If the Thread Execution Scheduling option is supported, and the threads involved in the lock are executing with the scheduling policies
SCHED_FIFOorSCHED_RR, the calling thread shall not acquire the lock if a writer holds the lock or if writers of higher or equal priority are blocked on the lock; otherwise, the calling thread shall acquire the lock.
Quoted 8 lines
Whereas the new version says:
If the Thread Execution Scheduling option is supported, and the threads that hold or are blocked on the lock are executing with the scheduling policies
SCHED_FIFOorSCHED_RR, the calling thread shall not acquire the lock if a writer holds the lock or if the calling thread does not already hold a read lock and writers of higher or equal priority are blocked on the lock; otherwise, the calling thread shall acquire the lock.
I wouldn't say that these tests are broken because of the change in POSIX. The change in POSIX only fixed the specs in the case of recursive locking that is situation where we have a thread that has rdlock and attempts to do rwlock while there is higher priority thread that attempts rwlock. In that situation the previous definition would caused deadlock.
But as far as I can see these tests do not attempt recursive locks, so that part of POSIX wasn't really problem.
Quoted 3 lines
This behaviour is not supported by default on GNU/Linux, so add a call to Glibc
pthread_rwlockattr_setkind_np()to set the correct lock kind as a prerequisite to the 2-1.c and 2-2.c tests.
This is where the problem is, glibc decided to deviate from the POSIX since they think that the standard is not well designed. That is a glibc design choice. I'm not againts working around that with requesting POSIX confirming variant on glibc, but the patch should clearly say this instead.
Also we should split this into two patches, one that adjusts the specs and one that adds glibc workaround.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp