diff options
author | Boris Nagaev <bnagaev@gmail.com> | 2017-02-03 12:31:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-03 12:31:09 (GMT) |
commit | 5a629857dfb4d55998627767669f087afc639568 (patch) | |
tree | f24c59ff37f14f7d493818fb1cd932e7daef75e0 /src/boost-test.cpp | |
parent | 56acbb7368a8bfeec32e9d5c3d441bd2d14751b3 (diff) | |
parent | b477bae14c12be5f4f8abe8e4d70f3c80e7f5403 (diff) | |
download | mxe-5a629857dfb4d55998627767669f087afc639568.zip mxe-5a629857dfb4d55998627767669f087afc639568.tar.gz mxe-5a629857dfb4d55998627767669f087afc639568.tar.bz2 |
Merge pull request #1657 from tonytheodore/boost-context
boost: add test for boost.context linking
Diffstat (limited to 'src/boost-test.cpp')
-rw-r--r-- | src/boost-test.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/boost-test.cpp b/src/boost-test.cpp index d975894..4dac283 100644 --- a/src/boost-test.cpp +++ b/src/boost-test.cpp @@ -9,6 +9,10 @@ boost::thread_specific_ptr<int> ptr; +// http://www.boost.org/doc/libs/1_60_0/libs/context/doc/html/context/context.html +#include <boost/context/all.hpp> +boost::context::fcontext_t fcm,fc1,fc2; + void test_thread() { if (ptr.get() == 0) { @@ -17,6 +21,23 @@ void test_thread() std::cout << "Hello, World! from thread" << std::endl; } +void f1(intptr_t) +{ + std::cout<<"f1: entered"<<std::endl; + std::cout<<"f1: call jump_fcontext( & fc1, fc2, 0)"<< std::endl; + boost::context::jump_fcontext(&fc1,fc2,0); + std::cout<<"f1: return"<<std::endl; + boost::context::jump_fcontext(&fc1,fcm,0); +} + +void f2(intptr_t) +{ + std::cout<<"f2: entered"<<std::endl; + std::cout<<"f2: call jump_fcontext( & fc2, fc1, 0)"<<std::endl; + boost::context::jump_fcontext(&fc2,fc1,0); + BOOST_ASSERT(false&&!"f2: never returns"); +} + int main(int argc, char *argv[]) { (void)argc; @@ -29,5 +50,15 @@ int main(int argc, char *argv[]) boost::thread thrd(test_thread); thrd.join(); + std::size_t size(8192); + void* sp1(std::malloc(size)); + void* sp2(std::malloc(size)); + + fc1=boost::context::make_fcontext(sp1,size,f1); + fc2=boost::context::make_fcontext(sp2,size,f2); + + std::cout<<"main: call jump_fcontext( & fcm, fc1, 0)"<<std::endl; + boost::context::jump_fcontext(&fcm,fc1,0); + return 0; } |