1 /* Copyright (C) 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
31 static char stacks
[N
][PTHREAD_STACK_MIN
];
32 static ucontext_t ctx
[N
][2];
33 static volatile int failures
;
39 /* Just to use the thread local descriptor. */
40 printf ("%ld: in %s now\n", n
, __FUNCTION__
);
48 int n
= (int) (long int) arg
;
50 if (getcontext (&ctx
[n
][1]) != 0)
52 printf ("%d: cannot get context: %m\n", n
);
56 printf ("%d: %s: before makecontext\n", n
, __FUNCTION__
);
58 ctx
[n
][1].uc_stack
.ss_sp
= stacks
[n
];
59 ctx
[n
][1].uc_stack
.ss_size
= PTHREAD_STACK_MIN
;
60 ctx
[n
][1].uc_link
= &ctx
[n
][0];
61 makecontext (&ctx
[n
][1], (void (*) (void)) fct
, 1, (long int) n
);
63 printf ("%d: %s: before swapcontext\n", n
, __FUNCTION__
);
65 if (swapcontext (&ctx
[n
][0], &ctx
[n
][1]) != 0)
68 printf ("%d: %s: swapcontext failed\n", n
, __FUNCTION__
);
71 printf ("%d: back in %s\n", n
, __FUNCTION__
);
77 static volatile int global
;
87 puts ("making contexts");
88 if (getcontext (&mctx
) != 0)
92 puts ("context handling not supported");
96 printf ("%s: getcontext: %m\n", __FUNCTION__
);
100 /* Play some tricks with this context. */
102 if (setcontext (&mctx
) != 0)
104 puts ("setcontext failed");
109 puts ("global not incremented twice");
114 for (n
= 0; n
< N
; ++n
)
115 if (pthread_create (&th
[n
], NULL
, tf
, (void *) (long int) n
) != 0)
117 puts ("create failed");
121 for (n
= 0; n
< N
; ++n
)
122 if (pthread_join (th
[n
], NULL
) != 0)
124 puts ("join failed");
131 #define TEST_FUNCTION do_test ()
132 #include "../test-skeleton.c"