0

I wrote a simple program in C++ like:

while(1){var+=1;var-=1;} 

and ran it, but it seems to only use 25% of CPU.

How can I increase the amount of CPU that my program will use, to 95%?

BartoszKP
  • 34,786
  • 15
  • 102
  • 130
Tez
  • 517
  • 1
  • 7
  • 16
  • I duped this to a C question since this question doesn't actually involve C++ specifics. (discussion here: http://chat.stackoverflow.com/transcript/message/20227431#20227431) – Mysticial Dec 02 '14 at 01:09

1 Answers1

2

Sounds like you're running this on a 4-processor system. You are using 100% of the CPU on one core. To use the other cores, you will have to write a multi-thread version of your application.

Multi-threading is very complicated, but there are lots of good tutorials out there; just hit up Google. Good luck!

elixenide
  • 44,308
  • 16
  • 74
  • 100
  • So basically, I have 4 cores, which means I need to set up 4 threads and have each thread run that same code? – Tez Dec 02 '14 at 01:09
  • Pretty much, yes. Exactly how you do it (processes versus threads) depends on which OS you're using; Windows and *nix systems (Unix, Linux, Mac OS X, Android, etc.) handle these things differently. – elixenide Dec 02 '14 at 01:10