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 9182745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:38:00+00:00 2026-06-17T18:38:00+00:00

I am using Boost::ASIO version 1.52.0 for a Windows client. I would like to

  • 0

I am using Boost::ASIO version 1.52.0 for a Windows client. I would like to be able to dedicate a thread to handling all receiving messages from the server, and then another dedicated thread to handle all outgoing messages to the server. I am using the same io_service object for both threads right now. What I’m worried about is that when the io_service::run() method is called, the thread that is handling the outgoing messages, might get scheduled to handle some incoming message calls and vice-a-versa. So, my question – is this possible? If it is, then would using a second io_service object solve the problem – one for each thread? Is there a better way to design this? I am trying to avoid using multiple threads for both the read and write handlers.

The other thing I would like confirmation on is – I have read that a lock should be used to single thread the code if 2 or more async_reads can be done at the same time. Likewise for async_writes. Should a lock also be used if an async_read can execute at the same time as an async_write, or should that be thread safe?

One last question – can the async methods – async_connect, async_read, and async_write all be called from a different thread before a worker thread has called the io_service run method?

  • 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-06-17T18:38:01+00:00Added an answer on June 17, 2026 at 6:38 pm

    You should use a single io_service, however many threads you use to invoke io_service::run() can also invoke handlers for asynchronous operations owned by the io_service. If these handlers access shared data structures, you will need to use a strand to ensure exclusive access. You’ll also need to ensure at most one write operation

    This operation is implemented in terms of zero or more calls to the
    stream’s async_write_some function, and is known as a composed
    operation
    . The program must ensure that the stream performs no other
    write operations (such as async_write, the stream’s async_write_some
    function, or any other composed operations that perform writes) until
    this operation completes.

    and read operation

    This operation is implemented in terms of zero or more calls to the
    stream’s async_read_some function, and is known as a composed
    operation
    . The program must ensure that the stream performs no other
    read operations (such as async_read, the stream’s async_read_some
    function, or any other composed operations that perform reads) until
    this operation completes.

    is outstanding for each socket.

    Using an io_service for all async_write() operations and another io_service for all async_read() operations is not possible because a single socket is serviced by one io_service that is passed in as a parameter in the constructor.

    In my experience most mult-io_service designs are driven by performance and latency requirements. The HTTP Server 2 example explores this with an io_service per CPU.

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

Sidebar

Related Questions

I have a very simple server/client performance test using boost::asio on Windows and it
I am using Boost Asio to set up a socket connection. I would like
I'm using boost::asio, and I have code like this: void CServer::Start(int port) { tcp::acceptor
I tried to make an asynchronous UDP client using boost::asio I get some code
In my project, I am extensively using boost asio to be able to uniformly
I'm using the Boost::asio to implement a client/server applicaion. The client code below is
I am using the latest version of boost and boost.asio. I have this class:
I am using boost::asio::ip::tcp::socket to send and receive data in a client/server application. I
I wrote a small tcp client using boost::asio, providing the following function: typedef boost::function<void(const
I'm trying to create an HTTP client using Boost Asio. I copied the sync

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.