0

If a multithreaded program runs safe on a single-core CPU with hyperthreading, will it also run safe on a dual-core CPU with hyperthreading? Concerning thread-safety etc.

EDIT

Ok, I try to be more specific. I mean the bad source code lines, where I will have forgotten or failed to make sure, that they won't be an (concurrency) issue.

So, maybe the 1-core htt "lies" by preventing dead-locks, crashes, cpu spikes or anything that my code causes on a 2-core machine. I'm unsure, how exactly 2 (logical) processors of a htt PC are different from 2 processors of a dual-core PC, how transparent htt is. If there's any issue, I'll probably buy a second PC just for that, that's why I asked.

Karl
  • 1
  • 1
  • Does "safe" mean that, when you ran your program repeatedly, it never happened to crash, or does it mean that you've made sure (by careful coding) that there won't be concurrency issues with your code? In the former case, you might've just been lucky; in the latter case, the number of CPU cores shouldn't (in theory) make a difference. – stakx - no longer contributing Dec 04 '10 at 10:36
  • I try to avoid concurrency issues. But I wonder, since my current PC is single-core, will a dual-core expose my program to more issues? In case my program is not well enaugh written, will the single-core htt PC crash less often? – Karl Dec 04 '10 at 11:04
  • ...Maybe dead-lock scenarios or anything. I guess, buying a dual-core machine is probably the best. Just tried to get convinced that in theory the single-core htt machine would be enaugh for testing. – Karl Dec 04 '10 at 11:11

1 Answers1

1

You're going to have to be more precise with your questions; just throwing "thread-safety etc." at the end of the question doesn't convince me you know what using threads means. What language is the multithreaded application even written in, what OS version are you using, what chipset are you considering?

Regardless, the answer is - hyperthreading "lies" to the OS and convinces it that there are more physical cores in the machine than there really are. From the OS's perspective, there is no difference between a single-core hyperthreaded config and a dual-core non-hyperthreaded config. A dual-core hyperthreaded config, by extension, merely doubles the number of apparent physical cores available.

I think you'll need to read specification papers with respect to the chipset your using to get a deeper knowledge of how hyperthreading is implemented and how it implements memory sharing and synchronization.

Asim Ihsan
  • 1,501
  • 8
  • 18
  • ah, found the relevant document: http://download.intel.com/design/processor/manuals/253665.pdf. Page 2-22 is the first reference to hyperthreading. – Asim Ihsan Dec 04 '10 at 10:41
  • I forgot, OS: Windows 7, languages: C and assembly – Karl Dec 04 '10 at 11:39
  • Interesting. For such a modern OS I'd say you have nothing to worry about, and you're using languages that expose real OS threads without any coddling (as opposed to Python which exposes threads but uses a global lock to synchronize all of them).but when in doubt, test. – Asim Ihsan Dec 04 '10 at 12:10