Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1113847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:55:02+00:00 2026-05-17T02:55:02+00:00

In asio:: io_service I insert objects. asio:: io_service::run() runs in several threads. The possibility

  • 0

In asio:: io_service I insert objects. asio:: io_service::run() runs in several threads.
The possibility to expect the completion of any object in queue is necessary.
For example:

template <typename T>
struct handler {
   void operator()() {
      ....
   }
   T get() const {...}
};

asio::io_service ios;
ios.post(handler());
  1. How I can refer to the object in queue?
  2. How can I pause the main program loop, untill handler::operator() is executed?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:55:03+00:00Added an answer on May 17, 2026 at 2:55 am

    Here’s what I know so far:
    1. Several handlers are executing on several threads.
    2. Handlers run independently of each other. There is no synchronization needed between threads for data/race conditions.
    3. Get can be called on anyone handler. When called the handler should stop calculating and let another thread call handler::get().

    This really seems more like a multi-threading / concurrency question then a boost::asio question. At the moment I do not see a need to use an io_service. It seems like several threads could just be started without an io_service and some synchronization could be used between the threads.

    The thread calling Handler::get() needs to wait until the io_service thread running operator() completes its calculation before it can return.

    Consider using a condition variable. The handler::get() method can wait until the condition is met (i.e. operator() finishes its calculation). The io_service thread that runs operator() would notify the main thread through the condition variable.

    An example of one thread notifying another thread via a condition variable is here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I call boost::asio::serial_port::async_write_some() and asio::io_service::run() in the other thread. There is a callback given
I have many different threads ( boost::thread_pool ) to a boost::asio::io_service . The io_service
Boost.asio documentation doesn't support any ftp examples. `boost::asio::io_service io_service; tcp::resolver resolver(io_service); tcp::resolver::query query(www.boost.org, http);
I have a class, which has a boost::asio::io_service object. I want this object stored
io_service::poll_one Run the io_service object's event processing loop to execute one ready handler. vs
I have the following thread pool. #include <queue> #include <map> #include <boost/shared_ptr.hpp> #include <boost/asio/io_service.hpp>
In the following code: tcp::socket socket(io_service); tcp::endpoint ep(boost::asio::ip::address::from_string(addr), i); socket.async_connect(ep, &connect_handler); socket.close(); is it
This simple example fails to compile in VS2K8: io_service io2; shared_ptr<asio::deadline_timer> dt(make_shared<asio::deadline_timer>(io2, posix_time::seconds(20))); As
There is a very simple socket server implemented by boost::asio . tcp::acceptor a(io_service, tcp::endpoint(tcp::v4(),
Given two stream-oriented I/O objects in Asio , what is the simplest way to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.