This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[rfa/testsuite/threads] fix 'sleep' call in pthreads.c
- From: Michael Elizabeth Chastain <mec at shout dot net>
- To: gdb-patches at sources dot redhat dot com, msnyder at redhat dot com
- Date: Thu, 6 Nov 2003 14:36:40 -0500
- Subject: [rfa/testsuite/threads] fix 'sleep' call in pthreads.c
Here's a patch to gdb.threads/pthreads.c to fix the call to sleep,
as requested by Michael Snyder.
Testing: tested with gcc 2.95.3 and gcc 3.3.2, binutils 2.14,
with -gdwarf-2 and -gstabs+, on native i686-pc-linux-gnu.
There were no significant differences in the results.
Okay to commit?
Michael C
===
2003-11-06 Michael Chastain <mec@shout.net>
* gdb.threads/pthreads.c (my_sleep): Handle early return from sleep.
Index: pthreads.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.threads/pthreads.c,v
retrieving revision 1.5
diff -c -3 -p -r1.5 pthreads.c
*** pthreads.c 23 Oct 2003 04:43:54 -0000 1.5
--- pthreads.c 6 Nov 2003 19:31:41 -0000
*************** static pthread_attr_t null_attr;
*** 40,45 ****
--- 40,57 ----
static int verbose = 0;
+ /* When gdb is running, it sets hidden breakpoints in the thread
+ library. The signals caused by these hidden breakpoints can
+ cause system calls such as 'sleep' to return early. Pay attention
+ to the return value from 'sleep' to get the full sleep. */
+
+ static int my_sleep (int unslept)
+ {
+ while (unslept > 0)
+ unslept = sleep (unslept);
+ return unslept;
+ }
+
static void
common_routine (arg)
int arg;
*************** thread1 (void *arg)
*** 80,86 ****
if (verbose) printf("thread1 %d\n", pthread_self ());
z += i;
common_routine (1);
! sleep(1);
}
return (void *) 0;
}
--- 92,98 ----
if (verbose) printf("thread1 %d\n", pthread_self ());
z += i;
common_routine (1);
! my_sleep(1);
}
return (void *) 0;
}
*************** thread2 (void * arg)
*** 97,105 ****
if (verbose) printf("thread2 %d\n", pthread_self ());
k += i;
common_routine (2);
! sleep(1);
}
! sleep(100);
return (void *) 0;
}
--- 109,117 ----
if (verbose) printf("thread2 %d\n", pthread_self ());
k += i;
common_routine (2);
! my_sleep(1);
}
! my_sleep(100);
return (void *) 0;
}
*************** main(argc, argv)
*** 148,154 ****
exit (1);
}
if (verbose) printf ("Made thread %d\n", tid1);
! sleep (1);
if (pthread_create (&tid2, PTHREAD_CREATE_NULL_ARG2, thread2, (void *) 0xdeadbeef))
{
--- 160,166 ----
exit (1);
}
if (verbose) printf ("Made thread %d\n", tid1);
! my_sleep (1);
if (pthread_create (&tid2, PTHREAD_CREATE_NULL_ARG2, thread2, (void *) 0xdeadbeef))
{
*************** main(argc, argv)
*** 157,169 ****
}
if (verbose) printf("Made thread %d\n", tid2);
! sleep (1);
for (j = 1; j <= 10000000; j++)
{
if (verbose) printf("top %d\n", pthread_self ());
common_routine (0);
! sleep(1);
t += j;
}
--- 169,181 ----
}
if (verbose) printf("Made thread %d\n", tid2);
! my_sleep (1);
for (j = 1; j <= 10000000; j++)
{
if (verbose) printf("top %d\n", pthread_self ());
common_routine (0);
! my_sleep(1);
t += j;
}