aboutsummaryrefslogtreecommitdiff
path: root/tests/force_exit.c
blob: 94b9f3f7b0ad8f0cc2b249eeb11e2da39d83faea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <emscripten.h>

int result = 0;

void EMSCRIPTEN_KEEPALIVE success() {
  printf("success? %d\n", result);
  assert(result == 10);
  result += 7;
  REPORT_RESULT();
}

void EMSCRIPTEN_KEEPALIVE later() {
  printf("later, now force an exit\n");
  result += 10;
  emscripten_force_exit(0);
}

int main() {
  atexit(success);

  EM_ASM({
    setTimeout(function() {
      Module._later();
    }, 1000);
  });

  printf("exit, but still alive\n");
  emscripten_exit_with_live_runtime();

  printf("HORRIBLE\n");
  result += 100; // should never happen

  return 0;
}