From adc3a37e96936c11862d113cf986a00fd277ff12 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Mon, 19 Aug 2024 08:53:10 -0500 Subject: [PATCH] Fix semaphore test (#4725) * Make counter in semaphore test an atomic variable * Revert using atomic counter and fix counter access outside of semaphore --- src/H5TSsemaphore.h | 2 +- test/ttsafe.c | 2 -- test/ttsafe.h | 2 -- test/ttsafe_semaphore.c | 14 ++++++++------ 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/H5TSsemaphore.h b/src/H5TSsemaphore.h index 0db1a888809..340b1cf9a11 100644 --- a/src/H5TSsemaphore.h +++ b/src/H5TSsemaphore.h @@ -179,7 +179,7 @@ H5TS_semaphore_wait(H5TS_semaphore_t *sem) * * Purpose: Increments (unlocks) the semaphore. If the semaphore's value * becomes greater than zero, then another thread blocked in a wait - * call will be woken up and proceed to lock the semaphore. + * call will proceed to lock the semaphore. * * Return: Non-negative on success / Negative on failure * diff --git a/test/ttsafe.c b/test/ttsafe.c index 08022eb1992..76dfa22bcbd 100644 --- a/test/ttsafe.c +++ b/test/ttsafe.c @@ -138,9 +138,7 @@ main(int argc, char *argv[]) AddTest("rec_rwlock_4", tts_rec_rw_lock_smoke_check_4, NULL, "recursive R/W lock smoke check 4 -- mixed mob", NULL); #endif /* !H5_HAVE_WIN_THREADS */ -#ifdef H5_HAVE_STDATOMIC_H AddTest("semaphore", tts_semaphore, NULL, "lightweight system semaphores", NULL); -#endif /* H5_HAVE_STDATOMIC_H */ #ifdef H5_HAVE_THREADSAFE AddTest("thread_id", tts_thread_id, NULL, "thread IDs", NULL); diff --git a/test/ttsafe.h b/test/ttsafe.h index d2066782b6b..f551e40462a 100644 --- a/test/ttsafe.h +++ b/test/ttsafe.h @@ -38,9 +38,7 @@ void tts_is_threadsafe(void); #ifdef H5_HAVE_THREADS void tts_thread_pool(void); void tts_atomics(void); -#ifdef H5_HAVE_STDATOMIC_H void tts_semaphore(void); -#endif /* H5_HAVE_STDATOMIC_H */ void tts_rec_rw_lock_smoke_check_1(void); void tts_rec_rw_lock_smoke_check_2(void); void tts_rec_rw_lock_smoke_check_3(void); diff --git a/test/ttsafe_semaphore.c b/test/ttsafe_semaphore.c index 41076632a4f..313508fe315 100644 --- a/test/ttsafe_semaphore.c +++ b/test/ttsafe_semaphore.c @@ -18,7 +18,7 @@ #include "ttsafe.h" -#if defined(H5_HAVE_THREADS) && defined(H5_HAVE_STDATOMIC_H) +#if defined(H5_HAVE_THREADS) #define NUM_PINGPONG (1000 * 1000) #define NUM_CLIENTSERVER (50 * 1000) @@ -40,6 +40,7 @@ static H5TS_THREAD_RETURN_TYPE ping(void *_test_info) { pingpong_t *test_info = (pingpong_t *)_test_info; + unsigned count; herr_t result; H5TS_thread_ret_t ret_value = 0; @@ -47,11 +48,11 @@ ping(void *_test_info) result = H5TS_semaphore_wait(&test_info->ping_sem); CHECK_I(result, "H5TS_semaphore_wait"); - test_info->counter++; + count = ++test_info->counter; result = H5TS_semaphore_signal(&test_info->pong_sem); CHECK_I(result, "H5TS_semaphore_signal"); - } while (test_info->counter < NUM_PINGPONG); + } while (count < NUM_PINGPONG); return ret_value; } @@ -60,6 +61,7 @@ static H5TS_THREAD_RETURN_TYPE pong(void *_test_info) { pingpong_t *test_info = (pingpong_t *)_test_info; + unsigned count; herr_t result; H5TS_thread_ret_t ret_value = 0; @@ -67,11 +69,11 @@ pong(void *_test_info) result = H5TS_semaphore_wait(&test_info->pong_sem); CHECK_I(result, "H5TS_semaphore_wait"); - test_info->counter++; + count = ++test_info->counter; result = H5TS_semaphore_signal(&test_info->ping_sem); CHECK_I(result, "H5TS_semaphore_signal"); - } while (test_info->counter < NUM_PINGPONG); + } while (count < NUM_PINGPONG); return ret_value; } @@ -268,4 +270,4 @@ tts_semaphore(void) tts_semaphore_clientserver(); } /* end tts_semaphore() */ -#endif /* defined(H5_HAVE_THREADS) && defined(H5_HAVE_STDATOMIC_H) */ +#endif /* defined(H5_HAVE_THREADS) */