A string is defined as a sequence of call event handles (non-parallel calls) that use strings to allow code execution in a multithreaded environment without using the displayed mutex. The string can be implicit or explicit, as shown in the alternative method below: Calling Io_service::run () in only one thread means that all event handles are executed using an implicit string because io_service ensures that the handle is only called internally by Run (). When there is an asynchronous operation chain associated with only one connection (for example, half-duplex protocol HTTP), it is not possible to execute the handle concurrently, which is an implicit string. An explicit string call is an instance of Io_service::strand, and all event handle functions need to be wrapped with io_service::strand::wrap () or advertised and sent through Io_service::strand objects. In the case of an asynchronous operation, such as Async_read () or Async_read_until (), if a completion handle passes through a strand, all other intermediate handles also need to pass through the same string, which is to ensure the thread safety of the objects that are shared between the caller and the completion operation ( In the case of Async_read () a socket, the caller can close the operation by close, which is done by embedding the hook function with the intermediate object that points to the custom handle associated with the final handle. struct my_handler{void operator () () {...}}; Template<class f>void Asio_handler_invoke (f F, my_handler*) {//do-custom invocation here. Default implementation calls F ();} Io_service::strand::wrap () Creates a new completion handle that defines the asio_handler_invoke so that the function object is executed through the Strand. The string of English is strand.
Using multithreading without an explicit lock