#include <AsyncFw/MainThread>
#include <AsyncFw/ThreadPool>
#include <AsyncFw/Log>
public:
using AsyncFw::ThreadPool::ThreadPool;
std::string text() { return "Pool"; }
};
int main(int argc, char *argv[]) {
AsyncFw::LogStream::setTimeFormat("%Y-%m-%d %H:%M:%S", true);
Pool *threadPool = AsyncFw::Instance<AsyncFw::ThreadPool>::create<Pool>("ExampeThreadPool");
logInfo() << threadPool->text();
_lt->
invokeMethod([]() { AsyncFw::Instance<AsyncFw::Log>::create(); },
true);
AsyncFw::ThreadPool::sync(_t, []() {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
logInfo() <<
"sync run in thread" << ct->
name() << ct->
id();
});
AsyncFw::ThreadPool::async([]() {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
logInfo() <<
"async run in thread" << ct->
name() << ct->
id();
});
AsyncFw::ThreadPool::async(
[]() {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
logInfo() <<
"async run in thread" << ct->
name() << ct->
id();
},
[]() {
logNotice() <<
"result without value, run in thread" << ct->
name() << ct->
id();
});
AsyncFw::ThreadPool::async(
[]() {
std::this_thread::sleep_for(std::chrono::milliseconds(15));
logInfo() <<
"async run in thread" << ct->
name() << ct->
id();
return 1;
},
[](int r) {
logNotice() <<
"result:" << r <<
"run in thread" << ct->
name() << ct->
id();
AsyncFw::MainThread::exit(0);
});
AsyncFw::AbstractThreadPool::Thread *_t1 = AsyncFw::ThreadPool::instance()->createThread("DestroyFromThreadExample");
logNotice() << "Start Applicaiton";
int ret = AsyncFw::MainThread::exec();
logNotice() << "End Applicaiton" << ret;
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
std::enable_if< std::is_void< typenamestd::invoke_result< M >::type >::value, bool >::type invokeMethod(M method, bool sync=false) const
Runs a method in a managed thread.
Definition AbstractThread.h:79
static AbstractThread * currentThread()
Returns a pointer to the AsyncFw::AbstractThread that manages the currently executing thread.
Definition AbstractThread.cpp:297
Управляет набором многократно используемых рабочих потоков для параллельного выполнения задач,...
Definition ThreadPool.h:52