• 0

[C++] Multithreading on Core 2 Duo


Question

Basically, I will be running two tasks concurrently on Windows XP, one will be very large (needing a whole core), and the other will be very small, and could easily run with the OS. The exchange between the tasks is an array, one basically formats the current array while the other processes the next array.

If I simply multithread my code (using the windows.h CreateThread() function), will Windows be smart enough to break up my program into the separate threads and distribute them across both cores? Will it always try to optimize the distribution of threads, or is there a way I can specify which core to run each thread on?

Or, if it won't break up my program automatically, would I be better to create processes instead of threads? Would that ensure that Windows could break up the tasks?

Thanks in advance!

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0
If I simply multithread my code (using the windows.h CreateThread() function), will Windows be smart enough to break up my program into the separate threads and distribute them across both cores? Will it always try to optimize the distribution of threads, or is there a way I can specify which core to run each thread on?

When you call CreateThread, you are breaking the program up into seperate threads. A thread is a thread, and there's nothing more Windows has to do. The scheduler will then run your threads on whatever processors/cores it finds most appropriate. The only way to make sure each threads runs on a specific processor is by first checking the affinity of your process, and then setting the affinity of each thread.

However, if you're looking to get the best possible performance, you should consider splitting the large task into X parts and running each part simultaneously on its own processor/core.

Link to comment
Share on other sites

  • 0

Thanks hdood! The large task is one huge algorithm that has to run sequentially (not even my code--it was purchased). Sounds like standard multithreading is fine then, but I will look into affinities.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.