Ticket #12340: test_correct.cpp

File test_correct.cpp, 844 bytes (added by anonymous, 6 years ago)

ignore previous test please.

Line 
1#include <boost/context/all.hpp>
2#include <thread>
3#include <Windows.h>
4
5void rec(unsigned int i)
6{
7 printf("%d\n", i);
8 uint8_t test[4096];
9 test[0] = rand();
10 rec(i + 1);
11}
12
13void test()
14{
15 puts("test()");
16 __try {
17 rec(1);
18 } __except (EXCEPTION_EXECUTE_HANDLER) {
19 puts("caught something");
20 }
21}
22
23int main()
24{
25 //unbuffer stdout
26 setvbuf(stdout, (char *)NULL, _IONBF, 0);
27
28 std::thread thr1([] {
29 test();
30 });
31 thr1.join();
32 puts("joined");
33 Sleep(1000);
34 puts("slept");
35
36 using ctx_t = boost::context::execution_context<void>;
37 std::thread thr2([] {
38 ctx_t ctx([](ctx_t c) {
39 puts("started context");
40 test(); // triggers an access violation that's not caught
41 return c;
42 });
43 ctx = ctx();
44 });
45 thr2.join();
46 puts("joined");
47 return 0;
48}