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

The Archive Base Latest Questions

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

The server is intended to be a multithreaded server which spawns new threads upon

  • 0

The server is intended to be a multithreaded server which spawns new threads upon either a producer or consumer connection via TCP. My problem is that I’m getting stuck in a wait state once a producer client fills the queue. This snippet shows the server’s handling of a producer connection. The format of the request the producer sends is PUT (item)

    reqline[0] = strtok (mesg, " \t\n");


 if ( strncmp(reqline[0], "PUT\0", 4)==0 )
           {
            item[0]=strtok(NULL," \t\n");
            pthread_create (&pro, NULL, producer, fifo);
            pthread_join (pro, NULL);


            }

So you can see I’m creating a new thread which handles the job of filling the queue/detecting when it is empty. The code within producer:

    queue *fifo;
    int i=atoi(item[0]);
    char*fullmsg="Full\n";

    fifo = (queue *)q;

    pthread_mutex_lock (fifo->mut);

         while (fifo->full) { //the problem  block

              printf ("producer: queue FULL.\n");
              send(conn_s, fullmsg,strlen(fullmsg),0);
              pthread_cond_wait (fifo->notFull, fifo->mut);
           } 

           queueAdd (fifo, 0);
           pthread_mutex_unlock (fifo->mut);
           pthread_cond_signal (fifo->notEmpty);

I believe the wait condition is the problem. The server is obviously waiting for a condition which can never be met, considering a consumer thread was not started to eat up the queue. I was thinking that I should change the condition to wait for an incoming consumer connection and then start a consumer thread. But then it seems silly to do so within this method. If I send a consumer request while in this state nothing happens.

Any suggestions are greatly appreciated. I’m not sure if this design is feasible.

  • 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-31T02:18:51+00:00Added an answer on May 31, 2026 at 2:18 am

    Your problem seems to be that you’re calling pthread_join() immediately after pthread_create(), which means that the main thread stops here until the producer exits – it can’t ever accept a consumer connection, so the producer can’t make progress once the queue is full.

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

Sidebar

Related Questions

We are intended to develop a service, which always stay connected to email server,
Which is best tcp socket server to testing html5websocket? I developing a html5socket based
I have a web server located in Switzerland and it is intended to serve
My question is similar to this MySQL question, but intended for SQL Server: Is
Server works fine, but the problem is the client doesn't receive anything. server.php <?php
The following code is intended to retrieve a file via FTP. However, I'm getting
I have the following SQL statement (that is intended for SQL Server): INSERT INTO
In the apache server installation I have a .conf file which forwards all requests
My SOAP server is (intended to be) setup with three operations: login, logout, and
I am building an android game which is intended to be a multiplayer game.

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.