mirror of
https://github.com/boostorg/asio.git
synced 2026-01-26 06:12:08 +00:00
Change spawn() to be a completion token-based async operation.
Added new spawn() overloads that conform to the requirements for asynchronous operations. These overloads also support cancellation. When targeting C++11 and later these functions are implemented in terms of Boost.Context directly. The existing overloads have been retained but are deprecated.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include <boost/asio/detached.hpp>
|
||||
#include <boost/asio/dispatch.hpp>
|
||||
#include <boost/asio/post.hpp>
|
||||
#include <boost/asio/spawn.hpp>
|
||||
@@ -19,6 +20,7 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using boost::asio::detached_t;
|
||||
using boost::asio::dispatch;
|
||||
using boost::asio::spawn;
|
||||
using boost::asio::strand;
|
||||
@@ -74,8 +76,10 @@ int main(int argc, char* argv[])
|
||||
for (int argn = 2; argn < argc; ++argn)
|
||||
{
|
||||
std::string input_file = argv[argn];
|
||||
spawn(pool, boost::bind(&search_file, search_string,
|
||||
input_file, output_strand, boost::placeholders::_1));
|
||||
spawn(pool,
|
||||
boost::bind(&search_file, search_string,
|
||||
input_file, output_strand, boost::placeholders::_1),
|
||||
detached_t());
|
||||
}
|
||||
|
||||
// Join the thread pool to wait for all the spawned tasks to complete.
|
||||
|
||||
Reference in New Issue
Block a user