main.cpp 677 Bytes
Newer Older
1
#include <utility>
2
#include <cstdio>
3 4 5 6 7 8 9 10 11

#include "context_switcher/context_switcher.h"

// Memory for custom stack and continuation semantics
const size_t STACK_SIZE = 512 * 8;
char custom_stack_1[STACK_SIZE];

// Force disable optimization
volatile int value = 0;
12

13
int main() {
14
  using namespace context_switcher;
15

16 17 18 19 20 21 22 23 24 25
  printf("Main 1!\n");
  auto cont_2 = enter_context(custom_stack_1, STACK_SIZE, [](continuation &&cont_main) {
    printf("Stack 1!\n");
    cont_main = switch_context(std::move(cont_main));
    printf("Stack 2!\n");
    return std::move(cont_main);
  });
  printf("Main 2!\n");
  cont_2 = switch_context(std::move(cont_2));
  printf("Main 3!\n");
26
  return 0;
27
}