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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:17:32+00:00 2026-06-17T23:17:32+00:00

I am developing a C++ application in Qt . I have a very basic

  • 0

I am developing a C++ application in Qt.
I have a very basic doubt, please forgive me if this is too stupid…

How many threads should I create to divide a task amongst them for minimum time?

I am asking this because my laptop is 3rd gen i5 processor (3210m). So since it is dual core & NO_OF_PROCESSORS environment variable is showing me 4. I had read in an article that dynamic memory for an application is only available for that processor which launched that application. So should I create only 1 thread (since env variable says 4 processors) or 2 threads (since my processor is dual core & env variable might be suggesting the no of cores) or 4 threads (if that article was wrong)?
Please forgive me since I am a beginner level programmer trying to learn Qt.
Thank You 🙂

  • 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-17T23:17:34+00:00Added an answer on June 17, 2026 at 11:17 pm

    NO_OF_PROCESSORS shows 4 because your CPU has Hyper-threading. Hyper-threading is the Intel trademark for tech that enables a single core to execute 2 threads of the same application more or less at the same time. It work as long as e.g. one thread is fetching data and the other one accessing the ALU. If both need the same resource and instructions can’t be reordered, one thread will stall. This is the reason you see 4 cores, even though you have 2.

    That dynamic memory is only available to one of the Cores is IMO not quite right, but register contents and sometimes cache content is. Everything that resides in the RAM should be available to all CPUs.

    More threads than CPUs can help, depending on how you operating systems scheduler works / how you access data etc. To find that you’ll have to benchmark your code. Everything else will just be guesswork.

    Apart from that, if you’re trying to learn Qt, this is maybe not the right thing to worry about…

    Edit:

    Answering your question: We can’t really tell you how much slower/faster your program will run if you increase the number of threads. Depending on what you are doing this will change. If you are e.g. waiting for responses from the network you could increase the number of threads much more. If your threads are all using the same hardware 4 threads might not perform better than 1. The best way is to simply benchmark your code.

    In an ideal world, if you are ‘just’ crunching numbers should not make a difference if you have 4 or 8 threads running, the net time should be the same (neglecting time for context switches etc.) just the response time will differ. The thing is that nothing is ideal, we have caches, your CPUs all access the same memory over the same bus, so in the end they compete for access to resources. Then you also have an operating system that might or might not schedule a thread/process at a given time.

    You also asked for an Explanation of synchronization overhead: If all your threads access the same data structures, you will have to do some locking etc. so that no thread accesses the data in an invalid state while it is being updated.

    Assume you have two threads, both doing the same thing:

    int sum = 0; // global variable
    
    thread() {
        int i = sum;
        i += 1;
        sum = i;
    }
    

    If you start two threads doing this at the same time, you can not reliably predict the output: It might happen like this:

    THREAD A : i = sum; // i = 0
               i += 1;  // i = 1
    **context switch**
    THREAD B : i = sum; // i = 0
               i += 1;  // i = 1
               sum = i; // sum = 1
    **context switch**
    THREAD A : sum = i; // sum = 1
    

    In the end sum is 1, not 2 even though you started the thread twice.
    To avoid this you have to synchronize access to sum, the shared data. Normally you would do this by blocking access to sum as long as needed. Synchronization overhead is the time that threads would be waiting until the resource is unlocked again, doing nothing.

    If you have discrete work packages for each thread and no shared resources you should have no synchronization overhead.

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

Sidebar

Related Questions

I am developing an Android application with MapView and I have a very strange
I have been developing an application for iPad that is very graphically intensive. I
I am developing an iPad application with SDK4.2. I have a very strange error
I'm developing this app which as a very basic Ajax form and I'm currently
Hello i am very new on developing application. I have worked with my friend
As i am developing the web application in J2EE, i have to be very
While developing my WordPress application i have a requirement where i need to show
I'm developing an iPhone application that have a TabBarController with two tabs. Each tab
I am developing an xbap application and have run into a problem with users
I am developing an application where i have to show iAds in all the

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.