Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / beast / example / http / server / stackless / http_server_stackless.cpp
index f0c7816..2439c68 100644 (file)
@@ -17,6 +17,7 @@
 #include <boost/beast/http.hpp>
 #include <boost/beast/version.hpp>
 #include <boost/asio/coroutine.hpp>
+#include <boost/asio/dispatch.hpp>
 #include <boost/asio/strand.hpp>
 #include <boost/config.hpp>
 #include <algorithm>
@@ -278,7 +279,16 @@ public:
     void
     run()
     {
-        loop(false, {}, 0);
+        // We need to be executing within a strand to perform async operations
+        // on the I/O objects in this session. Although not strictly necessary
+        // for single-threaded contexts, this example code is written to be
+        // thread-safe by default.
+        net::dispatch(stream_.get_executor(),
+                      beast::bind_front_handler(&session::loop,
+                                                shared_from_this(),
+                                                false,
+                                                beast::error_code{},
+                                                0));
     }
 
     #include <boost/asio/yield.hpp>