Boost logo

Boost Users :

Subject: [Boost-users] io_service::stop() call safe from within post()ed functor?
From: Dom Driver (domdriver_at_[hidden])
Date: 2011-03-24 21:57:24


Hi guys,

Picture a server class with the following methods (pseudocode):

void Server::Work()
{
    // Start the Async receive.
    mSocket.async_receive_from( *blah* ) );

    // Start the Async IO service.
    mASIOService.run();
}

void Server::Start()

{

    // Launch a new thread to do the work.

    mThread = boost::thread( boost::bind( &Server::Work, this ) );

}

void Server::Stop()
{
    // Post the stop request to the io_service.
    mASIOService.post( boost::bind( &Server::DoStop, this ) );

    // Join the comms thread.
    mThread.join();

}

void Server::DoStop()

{

    // Actually stop the io_service.
  
mASIOService.stop();

}

Assuming handling of packets is all correctly implemented, is it safe for the user to simply call the Stop() object method to stop the server?

Basically, can a function that's been post()ed to an io_service call io_service.stop() for that io_service?

TIA,

Dom

                                               



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net