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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:54:00+00:00 2026-05-28T06:54:00+00:00

Is I am looking at writing a multithreaded tcp server using boost ASIO. I

  • 0

Is I am looking at writing a multithreaded tcp server using boost ASIO. I have read through the tutorials and had a look at some of the examples and just want to check that my understanding is correct.

The server will accept connections then service requests from multiple clients.

My understanding is as follows:

  1. The server uses “a single io_service and a thread pool calling io_service::run()“
  2. All threads call io_service::run().
  3. The calls to io_service::run() are not within a strand, ergo completion handlers can run simultaneously.
  4. When a request arrives one of the threads is chosen, its read handler will be called
  5. Another request may arrive,starting the read handler on a second thread
  6. When one of the threads has finished handling the request it calls async_write, from within a strand
  7. Another thread also finishes processing its request, it also calls async_write, from within a strand
  8. The writes to the io_service are serialised via the strand, ergo they are thread safe.
  9. When the write operation completes the thread calls async_read()
  10. This call is not protected by a strand and the thread will be used for handling requests

Is my understanding correct? Is this solution vulnerable to race conditions?

  • 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-28T06:54:01+00:00Added an answer on May 28, 2026 at 6:54 am

    As Sam miller said, your assumptions are quite correct.

    However I would like to point out an issue that you may have not spotted.

    It is right that strands will serialize async_write(s) and therefore there will be thread safe.
    But the issue is not here, async_write is by itself thread safe if not used on the same socket. And strands will not help here since you should not interleave async_write on the same socket.

    Strands will not wait the previous async_write to finish before calling the next one. you will have to create a structure that async_write only if none is already in action on the socket.

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

Sidebar

Related Questions

I am looking into writing a self contained http server using Qt libraries, although
I am looking into writing a web-based vehicle tracking system. The framework I have
so got a new problem... I'm writing a multithreaded proxychecker in c#. I'm using
that's what I have: a Windows Service C# multithreaded the service uses a Read-Write-Lock
I am looking into writing web based games using just Javascript, HTML, and CSS.
I'm looking at writing some code that performs shadow mapping, in DX9. The sample
I am currently looking into writing a plugin for mysql in C. I have
I am looking at writing some software that will allow me to listen to
I am looking into writing my application's log files to a syslog server in
I am looking for a Python library for writing Jabber/XMPP clients using the Twisted

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.