优化io_context管理,添加工作保护和线程处理,确保资源正确释放
This commit is contained in:
@@ -35,6 +35,10 @@ int main()
|
|||||||
}
|
}
|
||||||
|
|
||||||
boost::asio::io_context io_context;
|
boost::asio::io_context io_context;
|
||||||
|
auto work_guard = boost::asio::make_work_guard(io_context);
|
||||||
|
std::thread io_thread([&io_context]() {
|
||||||
|
io_context.run();
|
||||||
|
});
|
||||||
|
|
||||||
// Initialize Steam Networking Manager
|
// Initialize Steam Networking Manager
|
||||||
SteamNetworkingManager steamManager;
|
SteamNetworkingManager steamManager;
|
||||||
@@ -285,6 +289,15 @@ int main()
|
|||||||
{
|
{
|
||||||
server->stop();
|
server->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stop io_context and join thread
|
||||||
|
work_guard.reset();
|
||||||
|
io_context.stop();
|
||||||
|
if (io_thread.joinable())
|
||||||
|
{
|
||||||
|
io_thread.join();
|
||||||
|
}
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_Shutdown();
|
ImGui_ImplOpenGL3_Shutdown();
|
||||||
ImGui_ImplGlfw_Shutdown();
|
ImGui_ImplGlfw_Shutdown();
|
||||||
ImGui::DestroyContext();
|
ImGui::DestroyContext();
|
||||||
|
|||||||
Reference in New Issue
Block a user