Concurrent async requests

Hi! If I do something like this can I be sure that async requests will run concurrently? boost::asio::io_service io_service; client c(io_service, argv[1], argv[2]); client c1(io_service, argv[1], argv[2]); boost::thread tr1(boost::bind(&boost::asio::io_service::run, &io_service)); io_service.run(); tr1.join(); The client class is a class from boost.asio example. Vlad

On Wed, 23 May 2007 22:18:53 +0700, "Владислав Чернышов" <carter.subscribe@gmail.com> said:
Hi!
If I do something like this can I be sure that async requests will run concurrently? boost::asio::io_service io_service; client c(io_service, argv[1], argv[2]); client c1(io_service, argv[1], argv[2]); boost::thread tr1(boost::bind(&boost::asio::io_service::run, &io_service)); io_service.run(); tr1.join();
The client class is a class from boost.asio example.
What do you mean by "async requests"? With two threads calling io_service::run(), your completion handlers will be able to run concurrently. The actual asynchronous operations would run concurrently even if you only had one thread calling io_service::run(). Cheers, Chris

OK, I got it. By "async requests" I mean requests running concurrently, and I don't have to wait others to process available data. Am I right? Does asio use POSIX AIO in Linux implementation? I mean librt functions. How to make some other work while doing i/o operations in single threaded program? Thank you. 2007/5/25, Christopher Kohlhoff <chris@kohlhoff.com>:
On Wed, 23 May 2007 22:18:53 +0700, "Владислав Чернышов" <carter.subscribe@gmail.com> said:
Hi!
If I do something like this can I be sure that async requests will run concurrently? boost::asio::io_service io_service; client c(io_service, argv[1], argv[2]); client c1(io_service, argv[1], argv[2]); boost::thread tr1(boost::bind(&boost::asio::io_service::run, &io_service)); io_service.run(); tr1.join();
The client class is a class from boost.asio example.
What do you mean by "async requests"? With two threads calling io_service::run(), your completion handlers will be able to run concurrently. The actual asynchronous operations would run concurrently even if you only had one thread calling io_service::run().
Cheers, Chris _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

On Mon, 4 Jun 2007 03:12:08 +0700, "Владислав Чернышов" <carter.subscribe@gmail.com> said:
OK, I got it. By "async requests" I mean requests running concurrently, and I don't have to wait others to process available data. Am I right?
Yes.
Does asio use POSIX AIO in Linux implementation? I mean librt functions.
No, it uses epoll and non-blocking I/O to emulate asynchronous operations.
How to make some other work while doing i/o operations in single threaded program?
Here are two different approaches you could take: - If your program has given over control to io_service::run(), use a chain of posts() or maybe a deadline_timer to perform the work in small chunks. E.g.: void do_some_work() { // perform a small amount of work here // post this function again to do a bit more work. io_service.post(do_some_work); } - If you want the main program control to be your "other work", periodically call io_service::poll() to check for completed I/O operations and invoke the associated handlers. Cheers, Chris
participants (2)
-
Christopher Kohlhoff
-
Владислав Чернышов