dimanche 1 novembre 2015

What causes this Visual C++ Debug Error for asio server example?

I am following the asioref-1.10.6 example for the TCP server with asynchronous mode. I don't have boost, so I am using C++11 std thread to allow both server and client working in same project.

I encountered this error:

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

What I did:

  1. I put server example in a function asynServe()

    asio::io_service io_service;
    tcp_server server(io_service);
    backService = &io_service;
    io_service.run();
    
    
  2. put a main function, so it will wait for the client thread to finish.

    std::thread t1(asyncServe);
    std::thread t2(asyncClient);
    
    t2.join();
    tryshutdown();
    //t1.join();
    int a;
    std::cin >> a;
    
    
  3. Put a shutdown function which just calls backService->stop(); I want to stop the server thread when the client finishes the job.

What happened is if I don't have t1.join() in the main, the Abort/Retry/Ignore dialog will show up. If I have t1.join there, then it would not show this dialog. What causes this problem?

I put Linux tag because I finally will port this project to Linux. So I hope this solution is not going to cause Linux problem.

Aucun commentaire:

Enregistrer un commentaire