#include <AsyncFw/MainThread>
#include <AsyncFw/ThreadPool>
#include <AsyncFw/Coroutine>
#include <AsyncFw/Log>
AsyncFw::ThreadPool::async(
[h]() {
logInfo() <<
"task: run in thread" << ct->
name() << ct->
id();
std::this_thread::sleep_for(std::chrono::milliseconds(10));
},
[h]() {
logInfo() <<
"task: resume in thread" << ct->
name() << ct->
id();
h.resume();
});
});
co_await await;
logNotice() <<
"task: resumed in thread" << ct->
name() << ct->
id();
}
int main(int argc, char *argv[]) {
AsyncFw::Instance<AsyncFw::ThreadPool>::create("CoroutineExamplePool");
task();
AsyncFw::ThreadPool::async(
[h]() {
logInfo() <<
"coro_task: run in thread" << ct->
name() << ct->
id();
std::this_thread::sleep_for(std::chrono::milliseconds(15));
},
[h]() {
logInfo() <<
"coro_task: resume in thread" << ct->
name() << ct->
id();
h.resume();
});
});
co_await await;
logNotice() <<
"coro_task: resumed in thread" << ct->
name() << ct->
id();
AsyncFw::MainThread::exit(0);
});
coro_task();
logNotice() << "Start Applicaiton";
int ret = AsyncFw::MainThread::exec();
logNotice() << "End Applicaiton";
return ret;
}
The AbstractThread class provides the base functionality for thread management.
Definition AbstractThread.h:45
std::string name() const
Returns name of managed thread.
Definition AbstractThread.cpp:679
std::thread::id id() const
Returns unique identifier of managed thread.
Definition AbstractThread.cpp:677
static AbstractThread * currentThread()
Returns a pointer to the AsyncFw::AbstractThread that manages the currently executing thread.
Definition AbstractThread.cpp:297
The CoroutineAwait struct.
Definition Coroutine.h:53
The CoroutineTask struct.
Definition Coroutine.h:20