Use std::thread instead std::jthread(For builds with libc++)
This commit is contained in:
parent
587f8b25db
commit
f2f6f253ec
1 changed files with 7 additions and 2 deletions
|
@ -8,7 +8,7 @@ namespace cserver::engine::basic {
|
||||||
template <std::size_t Size = 0>
|
template <std::size_t Size = 0>
|
||||||
struct TaskProcessor {
|
struct TaskProcessor {
|
||||||
boost::asio::io_context ioContext;
|
boost::asio::io_context ioContext;
|
||||||
std::array<std::jthread, Size> pool;
|
std::array<std::thread, Size> pool;
|
||||||
static constexpr utempl::ConstexprString kName = "basicTaskProcessor";
|
static constexpr utempl::ConstexprString kName = "basicTaskProcessor";
|
||||||
inline constexpr TaskProcessor(auto, auto&) :
|
inline constexpr TaskProcessor(auto, auto&) :
|
||||||
ioContext{},
|
ioContext{},
|
||||||
|
@ -23,10 +23,15 @@ struct TaskProcessor {
|
||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
inline constexpr ~TaskProcessor() {
|
||||||
|
for(auto& thread : this->pool) {
|
||||||
|
thread.join();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
inline auto Run() {
|
inline auto Run() {
|
||||||
for(auto& thread : this->pool) {
|
for(auto& thread : this->pool) {
|
||||||
thread = std::jthread([&]{
|
thread = std::thread([&]{
|
||||||
boost::asio::executor_work_guard<decltype(this->ioContext.get_executor())> guard{this->ioContext.get_executor()};
|
boost::asio::executor_work_guard<decltype(this->ioContext.get_executor())> guard{this->ioContext.get_executor()};
|
||||||
this->ioContext.run();
|
this->ioContext.run();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue