Care must be taken to ensure that all operations on the io_context and any of its associated I/O objects (such as sockets and timers) occur in only one thread at a time.
BOOST_ASIO_CONCURRENCY_HINT_UNSAFE_IO
Care must be taken to ensure that the run functions on the io_context (i.e. run, run_for, run_until, run_one, run_one_for, run_one_until, poll, and poll_one), and all operations on the context's associated I/O objects (such as sockets and timers), occur in only one thread at a time.
I understand as follows. Am I understand correctly ?
Operation
UNSAFE
UNSAFE_IO
Examples
run operations
single
single
run, run_for, run_until, run_one, run_one_for, run_one_until, poll, and poll_one
the context's associated I/O objects
single
single
socket, timer
other operations on the io_context
single
multi
post, dispatch, defer
single: access from single thread only
multie: can access from multiple threads
UNSAFE: BOOST_ASIO_CONCURRENCY_HINT_UNSAFE
UNSAFE_IO: BOOST_ASIO_CONCURRENCY_HINT_UNSAFE_IO
Especially I want to confirm what is "other operations on the io_context". My examples are post, dispatch, and defer. I think that I can switch the executor using these function.
// on thread 1
boost::asio::dispatch( // dispatch is called from multiple threads. It is safe when I use UNSAFE_IO but unsafe if I use UNSAFE
boost::asio::bind_executor(
io_context_with_unsafe_io.get_executor(), // run() is called on thread 2
[...] {
// on thread 2
socket.async_read_some(...); // io_context_with_unsafe_io associated socket but it is safe
}
)
);
I've read https://www.boost.org/doc/html/boost_asio/overview/core/concurrency_hint.html
I want to clarify the following two descriptions:
I understand as follows. Am I understand correctly ?
Especially I want to confirm what is "other operations on the io_context". My examples are
post
,dispatch
, anddefer
. I think that I can switch the executor using these function.Is that right ?