tinyrpc/test/coroutine/main.cc

45 lines
723 B
C++
Raw Normal View History

2024-12-17 15:47:10 +08:00
#include "coroutine.hpp"
#include <iostream>
using namespace std;
using namespace tinyrpc;
Coroutine* co1;
Coroutine* co2;
void coro1() {
cout << "this is coro1 begin" << endl;
Coroutine::yeild();
cout << "this is coro1 end" << endl;
}
void coro2() {
cout << "this is coro2 begin" << endl;
Coroutine::yeild();
cout << "this is coro2 end" << endl;
}
int main() {
int stk_size = 4 * 1024 * 1024;
char* stk1 = static_cast<char*>(malloc(stk_size));
char* stk2 = static_cast<char*>(malloc(stk_size));
co1 = new Coroutine(stk_size, stk1, coro1);
co2 = new Coroutine(stk_size, stk2, coro2);
co1->resume();
co2->resume();
co1->resume();
co2->resume();
}