From e6113df791ae9a87d4b08ff0b222655f9781b044 Mon Sep 17 00:00:00 2001 From: Paul Floyd Date: Tue, 30 Apr 2024 07:58:38 +0200 Subject: [PATCH] DRD regtest: try to make drd/tests/pth_mutex_signal less flaky Use a loop of 1ms usleeps rather than a single 1s usleep. This is usually more releable in ensuring that there's a context switch and that signals get handled in the order that we want. --- drd/tests/pth_mutex_signal.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drd/tests/pth_mutex_signal.c b/drd/tests/pth_mutex_signal.c index 916afdfe59..c85c80a500 100644 --- a/drd/tests/pth_mutex_signal.c +++ b/drd/tests/pth_mutex_signal.c @@ -15,6 +15,14 @@ #define STACK_SIZE 1024 * 512 #define LONG_SLEEP_TIME 1000000 +void long_sleep(void) +{ + for (int i = 0; i < LONG_SLEEP_TIME; i += 1000) + { + usleep(1000); + } +} + void *contender_start(void *arg) { pthread_mutex_t *mutex = arg; @@ -82,19 +90,19 @@ int main () // wait until the thread is sleeping inside pthread_mutex_lock(). fprintf(stderr, "sleeping\n"); - usleep(LONG_SLEEP_TIME); + long_sleep(); // signal thread fprintf(stderr, "signalling\n"); pthread_kill(contender, SIGINT); fprintf(stderr, "sleeping\n"); - usleep(LONG_SLEEP_TIME); + long_sleep(); fprintf(stderr, "unlocking\n"); pthread_mutex_unlock(&mutex); - usleep(LONG_SLEEP_TIME); + long_sleep(); // finally wait for the thread fprintf(stderr, "joining thread\n"); -- 2.47.2