是什么原因导致这个Visual C ++调试错误的asio服务器示例?

时间:2015-11-01 23:50:44

标签: c++ c++11 boost-asio stdthread

更新

我打算使用detach,因为我的计划是关闭应用程序,所以我不需要加入。如果我错了,请纠正我。

原始问题

我正在关注具有异步模式的TCP服务器的asioref-1.10.6示例。我没有提升,所以我使用C ++ 11标准线程来允许服务器和客户端在同一个项目中工作。

我遇到了这个错误:

Debug Error! ... abort() has been called ) Press Retry to debug the application. Abort/Retry/Ignore

我做了什么:

  1. 我将服务器示例放在函数asynServe()

    asio::io_service io_service;
    tcp_server server(io_service);
    backService = &io_service;
    io_service.run();
    
  2. 放一个main函数,所以它会等待客户端线程完成。

    std::thread t1(asyncServe);
    std::thread t2(asyncClient);
    
    t2.join();
    tryshutdown();
    //t1.join();
    int a;
    std::cin >> a;
    
  3. 设置一个关闭函数,只调用backService-> stop();我想在客户端完成工作时停止服务器线程。

  4. 如果我在main中没有t1.join(),则会显示Abort / Retry / Ignore对话框。如果我在那里有t1.join,那么就不会显示这个对话框。是什么导致了这个问题?

    我放了Linux标签,因为我最终将这个项目移植到Linux。所以我希望这个解决方案不会导致Linux问题。

0 个答案:

没有答案