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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:45:09+00:00 2026-06-09T02:45:09+00:00

I have a web interface where the user submits some data and it gets

  • 0

I have a web interface where the user submits some data and it gets written to a database. In the background there is a C++ program which periodically checks the database for new entries. It then takes these entries, processes them and writes their result to a directory. It then proceeds to sleep and keep checking for new entries to process.

My question is in regards to adding multithreading to the C++ program. I have read that it’s generally a bad idea just to create a new thread every time you need a another job done, but rather add the jobs to a queue and disperse them out to a fixed number of threads that have already been created (say, 5 or so). Is this the proper design route to take for my situation? Also, if I understand pthread_join correctly, I don’t actually need to call it because I don’t want to wait for all of the jobs to finish before continuing to check for new updates to the database.

I just wanted to make sure I’m headed in the right direction, any affirmations/criticisms/resources?

  • 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-09T02:45:11+00:00Added an answer on June 9, 2026 at 2:45 am

    You should first decide whether you even need more than one thread – it sounds like checking the database and writing files at some given interval can be accomplished using only one thread. Multiple threads would become useful when you start having to write different data to multiple files simultaneously at non-regular intervals. You are correct that using a queue of sorts would be the best way to distribute these ‘jobs’ to your threads, and that using a thread pool will give you a little more control over how many ‘jobs’ you want running simultaneously at any given time. The pthread_join method is used when you want to make sure one thread doesn’t exit before another – I’ve used this mostly to make sure that the program’s initial thread doesn’t exit after creating the thread pool, as when the parent thread exits the program’s execution stops. Some psuedo code based on my comments below.

    main thread:

    spawn child threads
    while(some exit condition){
       check database for new jobs
       if(new jobs){
          acquire job queue mutex //mutexes ensures only one thread accesses shared 
          add job to queue        //data at a time
          signal on shared condition variable
          release job queue mutex 
       }
       sleep(some regular duration)
    }
    

    child thread:

    while(some exit condition){
       acquire job queue mutex
       if(job queue's size == 0){
          wait on the shared condition variable
       }
       grab job from queue
       release job queue mutex
       handle job
    }
    

    See here for pthread/mutex/CV usage notes.

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

Sidebar

Related Questions

I've got a web interface from which I will gather user data (username,pass,email,etc..) and
I have a core data object and a REST web interface that use different
Aim: to create user friendly web interface to linux program without any ssh (console)
I am creating a web interface to enable a user import data from text
We want to auto login users in phpMyAdmin. Now we have a web-interface, written
I have a web app where a user can assemble a user interface (such
Question: I have a web interface where a user can upload an XML file,
i have a webservice and a web interface for registered user. this section allow
I have a server with a web interface, through which a task is submitted
Lately I have seen many projects which have a web interface and backend in

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.