优化io_context管理,添加工作保护和线程处理,确保资源正确释放

This commit is contained in:
Ayndpa
2025-11-19 22:07:48 +08:00
parent e8a326be53
commit f045632a78

View File

@@ -35,6 +35,10 @@ int main()
}
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
SteamNetworkingManager steamManager;
@@ -285,6 +289,15 @@ int main()
{
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_ImplGlfw_Shutdown();
ImGui::DestroyContext();