8 #include "pt-machine.h"
13 #ifdef FLOATING_STACKS
14 static char stacks
[N
][8192];
15 static ucontext_t ctx
[N
][2];
16 static volatile int failures
;
21 /* Just to use the thread local descriptor. */
22 printf ("%ld: in %s now\n", n
, __FUNCTION__
);
29 int n
= (int) (long int) arg
;
31 if (getcontext (&ctx
[n
][1]) != 0)
33 printf ("%d: cannot get context: %m\n", n
);
37 printf ("%d: %s: before makecontext\n", n
, __FUNCTION__
);
39 ctx
[n
][1].uc_stack
.ss_sp
= stacks
[n
];
40 ctx
[n
][1].uc_stack
.ss_size
= 8192;
41 ctx
[n
][1].uc_link
= &ctx
[n
][0];
42 makecontext (&ctx
[n
][1], (void (*) (void)) fct
, 1, (long int) n
);
44 printf ("%d: %s: before swapcontext\n", n
, __FUNCTION__
);
46 if (swapcontext (&ctx
[n
][0], &ctx
[n
][1]) != 0)
49 printf ("%d: %s: swapcontext failed\n", n
, __FUNCTION__
);
52 printf ("%d: back in %s\n", n
, __FUNCTION__
);
59 #ifdef FLOATING_STACKS
60 static volatile int global
;
66 #ifndef FLOATING_STACKS
67 puts ("not supported");
74 puts ("making contexts");
75 if (getcontext (&mctx
) != 0)
79 puts ("context handling not supported");
83 printf ("%s: getcontext: %m\n", __FUNCTION__
);
87 /* Play some tricks with this context. */
89 if (setcontext (&mctx
) != 0)
91 printf ("%s: setcontext: %m\n", __FUNCTION__
);
96 printf ("%s: 'global' not incremented twice\n", __FUNCTION__
);
100 for (n
= 0; n
< N
; ++n
)
101 if (pthread_create (&th
[n
], NULL
, threadfct
, (void *) (long int) n
) != 0)
102 error (EXIT_FAILURE
, errno
, "cannot create all threads");
104 for (n
= 0; n
< N
; ++n
)
105 pthread_join (th
[n
], NULL
);