CPU usage program

S

Sethu

Hi everybody,

Can anyone give me a simple program which would consumes more CPU
usage (more than 50%) in windows?

Thanks,
Sethu
 
G

Guest

Hi everybody,

Can anyone give me a simple program which would consumes more CPU
usage (more than 50%) in windows?

int main()
{
while (true) {}
}

I welcome anyone to write a smaller one.

Of course, this will never consume more than 50% CPU on a multi-core
system, but you can always run more instances of it.
 
V

Victor Bazarov

Erik said:
int main()
{
while (true) {}
}

I welcome anyone to write a smaller one.

Yours:
int main(){while(true){}}

Mine:
int main(){while(1);}

Zeppe's:
int main(){for(;;);}

At least 4 and 5 symbols smaller (respectively). :)

V
 
J

Justin Spahr-Summers

This should produce a compile error. Calling main within your program is
forbidden.

Can you cite chapter and verse? I'm not criticizing what you're
saying... I'd just like official verification of it.
 
V

Victor Bazarov

Justin said:
Can you cite chapter and verse? I'm not criticizing what you're
saying... I'd just like official verification of it.

[basic.start.main]/3 begins with words "The function main shall
not be used (3.2) within a program."

V
 
G

Guest

Can you cite chapter and verse? I'm not criticizing what you're
saying... I'd just like official verification of it.

[basic.start.main]/3 "The function main shall not be used within a program."
 
G

Guest

Yours:
int main(){while(true){}}

Mine:
int main(){while(1);}

Zeppe's:
int main(){for(;;);}

At least 4 and 5 symbols smaller (respectively). :)

Yes, I asked for that. Though I was thinking more in terms of the size
of the executable.
 
U

UINDEX

Hi everybody,

Can anyone give me a simple program which would consumes more CPU
usage (more than 50%) in windows?

Thanks,
Sethu

this is a sample program which can consume one core.
call OnTest N(CPU number) times to consumes more CPU usage (more than
50%).

DWORD WINAPI UseOneCore(void * p)
{
while(true);
return 0;
}


void CMy00Dlg::OnTest()
{
::CreateThread(NULL,0,UseOneCore,NULL,0,NULL);
}
 
Z

Zeppe

Erik said:
Can you cite chapter and verse? I'm not criticizing what you're
saying... I'd just like official verification of it.

[basic.start.main]/3 "The function main shall not be used within a program."
Restated also in [expr.call]/9: Recursive calls are permitted, except to
the function named main (3.6.1).

Regards,

Zeppe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top