This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: [RFA/TESTSUITE] build schedlock.c on 64-bit platforms
Daniel Jacobowitz writes:
> On Thu, Apr 10, 2003 at 05:16:05PM +0200, Andreas Schwab wrote:
> > Andrew Cagney <ac131313 at redhat dot com> writes:
> >
> > |> > args[i] = 1;
> > |> >> - res = pthread_create(&threads[i], NULL, thread_function, (void *)i);
> > |> >>
> > |>
> > |> Try:
> > |>
> > |> (((char *) NULL) + i)
> > |>
> > |> and what ever the reverse of that is ....
> >
> > That is even less portable than the above.
>
> Really? What's non-portable about it?
Attempt #3....
Index: schedlock.c
===================================================================
RCS file: /cvs/uberbaum/gdb/testsuite/gdb.threads/schedlock.c,v
retrieving revision 1.2
diff -u -p -r1.2 schedlock.c
--- schedlock.c 23 Oct 2002 03:22:56 -0000 1.2
+++ schedlock.c 10 Apr 2003 16:04:37 -0000
@@ -18,18 +18,25 @@ int main() {
for (i = 0; i < NUM; i++)
{
args[i] = 1;
- res = pthread_create(&threads[i], NULL, thread_function, (void *)i);
+ res = pthread_create(&threads[i],
+ NULL,
+ thread_function,
+ (void *) (((char *) NULL) + i));
}
/* schedlock.exp: last thread start. */
args[i] = 1;
- thread_function ((void *) i);
+ thread_function ((void *) (((char *) NULL) + i));
exit(EXIT_SUCCESS);
}
void *thread_function(void *arg) {
- int my_number = (int) arg;
+
+ /* Use sick pointer arithmetic trick, to get an offset which is a
+ long. This will be silently converted to an int, which is of
+ smaller size on 64-bit platforms. */
+ int my_number = (char *) arg - (char *) NULL;
int *myp = &args[my_number];
/* Don't run forever. Run just short of it :) */