2
0
mirror of https://github.com/boostorg/context.git synced 2026-01-27 06:42:20 +00:00

update examples + execution_context impl

This commit is contained in:
Oliver Kowalke
2014-11-28 19:11:59 +01:00
parent db17670917
commit a5bc3d313e
5 changed files with 94 additions and 34 deletions

View File

@@ -8,6 +8,7 @@
#include <functional>
#include <iostream>
#include <sstream>
#include <thread>
#include <boost/context/fixedsize.hpp>
@@ -44,9 +45,6 @@ public:
void run() {
scan();
E();
if (next!='\0'){
exit(1);
}
}
private:
@@ -92,15 +90,15 @@ private:
typedef coroutine<char> coro_t;
int main() {
void foo() {
std::istringstream is("1+1");
// invert control flow
coro_t::pull_type seq(
boost::context::fixedsize(),
[&is]( coro_t::push_type & yield) {
boost::context::fixedsize(),
[&is]( coro_t::push_type & yield) {
Parser p(is,[&yield](char ch){ yield(ch); });
p.run();
});
});
// user-code pulls parsed data from parser
while(seq){
@@ -108,3 +106,10 @@ int main() {
seq();
}
}
int main() {
std::thread t1( foo);
std::thread t2( foo);
t1.join();
t2.join();
}