1 /* Copyright (c) 2010-2019. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #define _XOPEN_SOURCE 700
17 static void child(void)
19 /* switch back to the main context */
20 if (swapcontext(&uc_child, &uc_main) != 0)
24 int main(int argc, char *argv[])
26 void *stack = malloc(64 * 1024);
28 /* configure a child user-space context */
31 if (getcontext(&uc_child) != 0)
33 uc_child.uc_link = NULL;
34 uc_child.uc_stack.ss_sp = (char *) stack + (32 * 1024);
35 uc_child.uc_stack.ss_size = 32 * 1024;
36 uc_child.uc_stack.ss_flags = 0;
37 makecontext(&uc_child, child, 0);
39 /* switch into the user context */
40 if (swapcontext(&uc_main, &uc_child) != 0)
43 /* Fine, child came home */
46 /* die successfully */