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

  • Home
  • SEARCH
  • 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 9173485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:35:46+00:00 2026-06-17T16:35:46+00:00

my server uses non-blocking socket multiplexing. I want to use one thread for receiving

  • 0

my server uses non-blocking socket multiplexing.
I want to use one thread for receiving incoming connections and handle input and another thread for sending data over sockets. It will look like that:

reader_worker(...)
{
    ...
    select(fd_max+1, &read_set, NULL, NULL, NULL);
    ...
}

writer_worker(...)
{
    ...
    select(fd_max+1, NULL, &write_set, NULL, NULL);
    ...
}

Since I don’t want to miss incoming connections I can imagine it is better to receive and send in seperate threads. Do I have to lock the socket which might be in read_set as well as in write_set? Is this the correct approach or doesnt this method have any performance improvement?

  • 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-17T16:35:47+00:00Added an answer on June 17, 2026 at 4:35 pm

    You’re not going to miss any incoming connection if you do it in one thread. Even if you have large amounts of data to send or receive, the latency of a send() or recv() call is determined by the size of local buffers in the network stack rather, so you will be back quickly to accept incoming connections.

    Two thing though, where I’m not sure about your code samples:

    • Put the socket for accepting connections into the same array as the accepted connections for use in a single select() call. Unless you bind to different network interfaces, using multiple threads is not going to make you program run faster.
    • If you are handling incoming data, this is where a second thread becomes useful. In general, you have resources like you network interface card, CPU, hard disk. It is useful to have one thread per resource, i.e. one to handle network IO (receiving requests, sending responses) and a second one to handle the actual requests. If you have multiple cores, you can also make use of multiple threads for handling requests, provided that is a CPU-bound task. If all that these requests do is serving pictures from a single hard disk, using more than one thread for requests won’t give you any additional performance.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I like CKEditor and my server uses PHP. I want to use CKEditor to
We use a software which uses Sql server 2005 as back-end. The problem is
I want to make AJAX calls to a secure server that uses a self-signed
I have written a server that performs non-blocking IO using the Java NIO API.
I have an existing multi-threaded application which uses blocking connect() call. However, I want
I created a java server that uses standard, non-encrypted sockets and an android application
I'm developping a communication library based on NIO's non-blocking SocketChannels so I can use
My server uses port#1988 But I don't see any option in connection wizard where
Say a stored procedure on MSSQL Server uses an SQL transaction using BEGIN TRANSACTION/COMMIT
is device token changes each time when i opens my application? Apple server uses

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.