c++thread-safetyboost-asioboost-thread

Is boost::io_service::post thread safe?


Is it thread safe to post new handlers from within a handler? I.e. Can threads that called the io_service::run() post new Handlers to the same io_service?

Thanks


Solution

  • It is safe to post handlers from within a handler for a single instance of an io_service according to the documentation.

    Thread Safety

    Distinct objects: Safe.

    Shared objects: Safe, with the exception that calling reset() while there are unfinished run(), run_one(), poll() or poll_one() calls results in undefined behaviour.