Esempio 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;
}
Esempio n. 2
0
void fn3( std::string const& str)
{
    X x( str);
    intptr_t vp = gctx.suspend( value1);
    value1 = vp;
	BOOST_ASSERT( gctx.is_running() );
    gctx.suspend();
}
Esempio n. 3
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;
}
Esempio n. 4
0
int main( int argc, char * argv[])
{
    {
        ctx.resume();
    }

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

    return EXIT_SUCCESS;
}
Esempio n. 5
0
void fn()
{
    X x;

    for( int i = 0;; ++i)
    {
        std::cout << "fn(): " << i << std::endl;
        ctx.suspend();
    }
}
Esempio n. 6
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;
}
Esempio n. 7
0
void fn2() {
    std::cout << "inside function fn2(): fn2() returns return to fn()" << std::endl;
 //   ctx.resume();
    ctx2.suspend();
    std::cout << "finish fn2(), returning back to fn\n";
}
Esempio n. 8
0
void fn2()
{
    std::cout << "first time inside fn2()" << std::endl;
    ctx2.suspend();
    std::cout << "second time inside fn2(), returns to main()" << std::endl;
}
Esempio n. 9
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);
}