我打算使用detach,因为我的计划是关闭应用程序,所以我不需要加入。如果我错了,请纠正我。
我正在关注具有异步模式的TCP服务器的asioref-1.10.6示例。我没有提升,所以我使用C ++ 11标准线程来允许服务器和客户端在同一个项目中工作。
我遇到了这个错误:
Debug Error! ... abort() has been called ) Press Retry to debug the application. Abort/Retry/Ignore
我做了什么:
我将服务器示例放在函数asynServe()
中asio::io_service io_service;
tcp_server server(io_service);
backService = &io_service;
io_service.run();
放一个main函数,所以它会等待客户端线程完成。
std::thread t1(asyncServe);
std::thread t2(asyncClient);
t2.join();
tryshutdown();
//t1.join();
int a;
std::cin >> a;
设置一个关闭函数,只调用backService-> stop();我想在客户端完成工作时停止服务器线程。
如果我在main中没有t1.join(),则会显示Abort / Retry / Ignore对话框。如果我在那里有t1.join,那么就不会显示这个对话框。是什么导致了这个问题?
我放了Linux标签,因为我最终将这个项目移植到Linux。所以我希望这个解决方案不会导致Linux问题。