tinyrpc/test/coroutine/main.cc

45 lines
717 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;
2024-12-20 21:17:21 +08:00
// char* stk1 = static_cast<char*>(malloc(stk_size));
// char* stk2 = static_cast<char*>(malloc(stk_size));
co1 = new Coroutine(stk_size, coro1);
co2 = new Coroutine(stk_size, coro2);
2024-12-17 15:47:10 +08:00
co1->resume();
co2->resume();
co1->resume();
co2->resume();
}