]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
DRD regtest: try to make drd/tests/pth_mutex_signal less flaky
authorPaul Floyd <pjfloyd@wanadoo.fr>
Tue, 30 Apr 2024 05:58:38 +0000 (07:58 +0200)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Tue, 30 Apr 2024 05:58:38 +0000 (07:58 +0200)
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

index 916afdfe599f3cbd24f4cd77e7d6d9e7ef95e4d4..c85c80a500ff4eb356c198f3052089bd20e14af9 100644 (file)
 #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");