Exemplo n.º 1
0
void fn()
{
    std::cout << "inside function fn(), calling fn2\n";
    ctx2.resume();
    std::cout << "back in fn(), let fn2() complete()\n";
    ctx2.resume();
    std::cout << "fn() returns return to main()" << std::endl;
}
Exemplo n.º 2
0
int main( int argc, char * argv[])
{
    {
        ctx2 = boost::contexts::context(
            fn2, 
            boost::contexts::default_stacksize(),
			boost::contexts::no_stack_unwind, boost::contexts::return_to_caller);
        boost::contexts::context ctx1(
            fn1, 
            boost::contexts::default_stacksize(),
			boost::contexts::no_stack_unwind,
            ctx2);

        ctx1.start();
    }

    std::cout << "main(): ctx1 is destructed\n";

    std::cout << "main(): resume ctx2\n";
    ctx2.resume();

    std::cout << "Done" << std::endl;

    return EXIT_SUCCESS;
}
Exemplo n.º 3
0
void test_case_5()
{
    value1 = 1;
    BOOST_CHECK_EQUAL( 1, value1);
    BOOST_CHECK_EQUAL( std::string(""), value3);
    gctx = boost::contexts::context(
        fn3, "abc",
        boost::contexts::default_stacksize(),
        boost::contexts::stack_unwind, boost::contexts::return_to_caller);
    BOOST_CHECK( ! gctx.is_started() );
    BOOST_CHECK( ! gctx.is_complete() );
    intptr_t vp = gctx.start();
    BOOST_CHECK( gctx.is_started() );
    BOOST_CHECK( ! gctx.is_resumed() );
    BOOST_CHECK( ! gctx.is_complete() );
    BOOST_CHECK_EQUAL( vp, value1);
    BOOST_CHECK_EQUAL( 1, value1);
    int x = 7;
    vp = 0;
    vp = gctx.resume( x);
    BOOST_CHECK_EQUAL( 7, value1);
    BOOST_CHECK( ! vp);
    BOOST_CHECK( ! gctx.is_complete() );
    BOOST_CHECK( gctx.is_resumed() );
    BOOST_CHECK_EQUAL( std::string(""), value3);
    gctx.unwind_stack();
    BOOST_CHECK( gctx.is_complete() );
    BOOST_CHECK_EQUAL( std::string("abc"), value3);
}
Exemplo n.º 4
0
int main( int argc, char * argv[])
{
    {
        ctx.resume();
    }

    std::cout << "Done" << std::endl;

    return EXIT_SUCCESS;
}
Exemplo n.º 5
0
int main( int argc, char * argv[])
{
    ctx = boost::contexts::context(
            fn,
            boost::contexts::default_stacksize(),
			boost::contexts::no_stack_unwind, boost::contexts::return_to_caller);
    ctx.start();
    for ( int i = 0; i < 4; ++i)
    {
        ctx.resume();
    }

    std::cout << "ctx is complete: " << std::boolalpha << ctx.is_complete() << "\n";
    std::cout << "call ctx.unwind_stack()" << std::endl;
    ctx.unwind_stack();
    std::cout << "ctx is complete: " << std::boolalpha << ctx.is_complete() << "\n";

    std::cout << "Done" << std::endl;

    return EXIT_SUCCESS;
}