diff options
| author | Jörg Frings-Fürst <debian@jff.email> | 2026-03-10 13:24:07 +0100 |
|---|---|---|
| committer | Jörg Frings-Fürst <debian@jff.email> | 2026-03-10 13:24:07 +0100 |
| commit | cfd1f17f1a85d95ea12bca8dae42add7dad1ad11 (patch) | |
| tree | 8016486f8ee7157213f2d09ff2491bfa9c94638a /tests/test-pthread-rwlock.c | |
| parent | 14e4d584d0121031ec40e6c35869745f1747ff29 (diff) | |
| parent | 1403307d6e2fb4e7b5d97a35f40d1e95134561ab (diff) | |
Merge branch 'release/debian/1.4.2-1'HEADdebian/1.4.2-1master
Diffstat (limited to 'tests/test-pthread-rwlock.c')
| -rw-r--r-- | tests/test-pthread-rwlock.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/tests/test-pthread-rwlock.c b/tests/test-pthread-rwlock.c index 7ab8d5ee..0edd669c 100644 --- a/tests/test-pthread-rwlock.c +++ b/tests/test-pthread-rwlock.c @@ -1,5 +1,5 @@ /* Test of read-write locks in multithreaded situations. - Copyright (C) 2005, 2008-2024 Free Software Foundation, Inc. + Copyright (C) 2005, 2008-2026 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,6 +16,15 @@ /* Written by Bruno Haible <bruno@clisp.org>, 2005. */ +/* This test fails when writer starvation occurs + <https://en.wikipedia.org/wiki/Readers%E2%80%93writers_problem>. + It depends on the implementation of pthread rwlocks, cf. + <https://gitweb.git.savannah.gnu.org/gitweb/?p=gnulib/maint-tools.git;a=tree;f=test-programs/pthread-rwlock>, + as well as on the number of CPUs (because when there are >= 2*THREAD_COUNT + CPUs, the checker threads are more "efficient" at not giving away the + reader lock). + A failure was seen with musl libc/riscv64 on a machine with 64 CPUs. */ + #include <config.h> #if USE_ISOC_THREADS || USE_POSIX_THREADS || USE_ISOC_AND_POSIX_THREADS || USE_WINDOWS_THREADS @@ -93,10 +102,10 @@ random_account (void) static void check_accounts (void) { - int i, sum; + int sum; sum = 0; - for (i = 0; i < ACCOUNT_COUNT; i++) + for (int i = 0; i < ACCOUNT_COUNT; i++) sum += account[i]; if (sum != ACCOUNT_COUNT * 1000) abort (); @@ -114,9 +123,7 @@ static pthread_rwlock_t my_rwlock = PTHREAD_RWLOCK_INITIALIZER; static void * rwlock_mutator_thread (void *arg) { - int repeat; - - for (repeat = REPEAT_COUNT; repeat > 0; repeat--) + for (int repeat = REPEAT_COUNT; repeat > 0; repeat--) { int i1, i2, value; @@ -164,30 +171,29 @@ rwlock_checker_thread (void *arg) static void test_rwlock (void) { - int i; pthread_t checkerthreads[THREAD_COUNT]; pthread_t threads[THREAD_COUNT]; /* Initialization. */ - for (i = 0; i < ACCOUNT_COUNT; i++) + for (int i = 0; i < ACCOUNT_COUNT; i++) account[i] = 1000; init_atomic_int (&rwlock_checker_done); set_atomic_int_value (&rwlock_checker_done, 0); /* Spawn the threads. */ - for (i = 0; i < THREAD_COUNT; i++) + for (int i = 0; i < THREAD_COUNT; i++) ASSERT (pthread_create (&checkerthreads[i], NULL, rwlock_checker_thread, NULL) == 0); - for (i = 0; i < THREAD_COUNT; i++) + for (int i = 0; i < THREAD_COUNT; i++) ASSERT (pthread_create (&threads[i], NULL, rwlock_mutator_thread, NULL) == 0); /* Wait for the threads to terminate. */ - for (i = 0; i < THREAD_COUNT; i++) + for (int i = 0; i < THREAD_COUNT; i++) ASSERT (pthread_join (threads[i], NULL) == 0); set_atomic_int_value (&rwlock_checker_done, 1); - for (i = 0; i < THREAD_COUNT; i++) + for (int i = 0; i < THREAD_COUNT; i++) ASSERT (pthread_join (checkerthreads[i], NULL) == 0); check_accounts (); } |
