1 /* Ack, a hack! We need to get the proper definition, or lack thereof,
2 for FLOATING_STACKS. But when !IS_IN_libpthread, this can get defined
3 incidentally by <tls.h>. So kludge around it. */
5 #define IS_IN_libpthread
7 #undef IS_IN_libpthread
20 #ifdef FLOATING_STACKS
21 static char stacks[N][8192];
22 static ucontext_t ctx[N][2];
23 static volatile int failures;
28 /* Just to use the thread local descriptor. */
29 printf ("%ld: in %s now\n", n, __FUNCTION__);
36 int n = (int) (long int) arg;
38 if (getcontext (&ctx[n][1]) != 0)
40 printf ("%d: cannot get context: %m\n", n);
44 printf ("%d: %s: before makecontext\n", n, __FUNCTION__);
46 ctx[n][1].uc_stack.ss_sp = stacks[n];
47 ctx[n][1].uc_stack.ss_size = 8192;
48 ctx[n][1].uc_link = &ctx[n][0];
49 makecontext (&ctx[n][1], (void (*) (void)) fct, 1, (long int) n);
51 printf ("%d: %s: before swapcontext\n", n, __FUNCTION__);
53 if (swapcontext (&ctx[n][0], &ctx[n][1]) != 0)
56 printf ("%d: %s: swapcontext failed\n", n, __FUNCTION__);
59 printf ("%d: back in %s\n", n, __FUNCTION__);
66 #ifdef FLOATING_STACKS
67 static volatile int global;
73 #ifndef FLOATING_STACKS
74 puts ("not supported");
81 puts ("making contexts");
82 if (getcontext (&mctx) != 0)
86 puts ("context handling not supported");
90 printf ("%s: getcontext: %m\n", __FUNCTION__);
94 /* Play some tricks with this context. */
96 if (setcontext (&mctx) != 0)
98 printf ("%s: setcontext: %m\n", __FUNCTION__);
103 printf ("%s: 'global' not incremented twice\n", __FUNCTION__);
107 for (n = 0; n < N; ++n)
108 if (pthread_create (&th[n], NULL, threadfct, (void *) (long int) n) != 0)
109 error (EXIT_FAILURE, errno, "cannot create all threads");
111 for (n = 0; n < N; ++n)
112 pthread_join (th[n], NULL);