update copyright year printed by GDB, GDBserver and gdbreplay.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / attach-many-short-lived-threads.c
index 001f2ffe80aeca11d8e20d844c535adec11c1318..4a750228394b6b0136e25a067f617e2d6828f466 100644 (file)
@@ -113,6 +113,17 @@ detached_fn (void *arg)
   return NULL;
 }
 
+/* Allow for as much timeout as DejaGnu wants, plus a bit of
+   slack.  */
+#define SECONDS (TIMEOUT + 20)
+
+/* We'll exit after this many seconds.  */
+unsigned int seconds_left = SECONDS;
+
+/* GDB sets this whenever it's about to start a new detach/attach
+   sequence.  We react by resetting the seconds left counter.  */
+volatile int again = 0;
+
 int
 main (int argc, char *argv[])
 {
@@ -144,8 +155,20 @@ main (int argc, char *argv[])
       create_thread (&detached_attr, detached_fn, NULL);
     }
 
-  /* Long enough for all the attach/detach sequences done by the .exp
-     file.  */
-  sleep (180);
+  /* Exit after a while if GDB is gone/crashes.  But wait long enough
+     for one attach/detach sequence done by the .exp file.  */
+  while (--seconds_left > 0)
+    {
+      sleep (1);
+
+      if (again)
+       {
+         /* GDB should be reattaching soon.  Restart the timer.  */
+         again = 0;
+         seconds_left = SECONDS;
+       }
+    }
+
+  printf ("timeout, exiting\n");
   return 0;
 }
This page took 0.025381 seconds and 4 git commands to generate.