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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:50:33+00:00 2026-05-31T20:50:33+00:00

Im designing a multi cleint web server using multithreads in C using Pthreads, i

  • 0

Im designing a multi cleint web server using multithreads in C using Pthreads, i have a Masterthread that is in a loop doing the listening, when there is a connection it spawns a new thread doing a function to serve, while the Masterthread continue listening for connection.

as i have notice from debuging, its serving only one connection at a time, the Accept() system call is waiting for that connection to close, then it will spawn the next connection in the queue.

Its acting like if its a single-thread web server.

    void *ServeThread(void *param)
{    int tsk;
     tsk = (int)param;

    /* here im serving the connection (tsk), and then close it */
}

void *MakeThreadPool(void *param)
{

    for(;;) {
        length = sizeof(cli_addr);
        if((socketfd = accept(listenfd, (struct sockaddr *)&cli_addr, &length)) < 0) { 
            exit(1);
                                                  }
    temps=socketfd;
    rc = pthread_create(&Thread[i++],NULL,ServeThread,(void *)temps);

                        }
}

How can i make accpet() contine listening al spawning theads when ever there is a connection without waiting for the previous one to finish ?

  • 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-31T20:50:35+00:00Added an answer on May 31, 2026 at 8:50 pm

    You observation is not correct, accept(2) does not wait for established TCP connection to complete. What you see is probably thread dispatch artifact – the main thread is preempted by the newly spawned thread and does not get to run until that one completes.

    In general, thread-per-connection is a workable strategy, but you might want to create a pool of threads before accepting connection, instead of starting a new one every time.

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

Sidebar

Related Questions

I'm in a process of designing a multi-tier ASP.NET web application that is supposed
I am designing a multi tenants web portal application using MVC. Tenants will be
I am designing a multi-tennant web-based SaaS application that will be hosted on Windows
I am designing a multi-file upload service that also shows upload progress for each
When designing a client/server architecture, is there any advantage to multiplexing multiple connections from
When designing a web service that will allow the consumer of the service to
I'm in the beginning stages of designing an application using Prism and have a
I'm designing a game server and I have never done anything like this before.
I am designing the architecture of a new web site. Since multi-tier architecture definitely
I am designing a web app that has some information that needs to be

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.