100% CPU Usage...

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
Alexis Blaze
New poster
Posts: 8
Joined: Thu Jul 13, 2006 8:36 am
Location: Indonesia
Contact:

100% CPU Usage...

Post by Alexis Blaze »

hi all.. i was developing a new software for my college project.. it was acting as a middletier between application and database for safety reason... the software works fine but when i look at task manager->performance, when my software ran, cpu time will rise up to 100%...

here's a little look at how my software works logically...

BEGIN LISTING
-----------------------------------------------------------------------------
// this will load up some configuration and prepare the socket
middleTier.InitMiddleTier();

while(!middleTier.isShutDown()) {
// here i will see if the socket active (is any client trying to connect)
if(middleTier.peekSocket()) {
// if the socket is active, accept the connection, then create a thread
// for handling further request from that client
middleTier.addClient();
}
}

// the middleTier has been closed/died, cleanup
middleTier.cleanUp();
-------------------------------------------------------------------------------
END LISTING

can you spot the problem why my software would eat up cpu time to 100%?
Krzysztof Duleba
Guru
Posts: 584
Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland
Contact:

Post by Krzysztof Duleba »

You should be using select instead of active waiting. Use Google to find more info about it.
For millions of years, mankind lived just like the animals. Then something happened which unleashed the power of our imagination. We learned to talk and we learned to listen...
Alexis Blaze
New poster
Posts: 8
Joined: Thu Jul 13, 2006 8:36 am
Location: Indonesia
Contact:

Post by Alexis Blaze »

The middleTier.peekSocket() method is actually a select with error handling, but it's on unblocking state...

The problem is, if the select is blocking, then when i stop the application then it will still waiting for a client...

Can we somehow notify the select to stop waiting?
Krzysztof Duleba
Guru
Posts: 584
Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland
Contact:

Post by Krzysztof Duleba »

Select would be useless if it couldn't handle it, would it? You can use exception sets, you can set a timeout. Read the manual or look for examples, there are plenty of them on the web.
For millions of years, mankind lived just like the animals. Then something happened which unleashed the power of our imagination. We learned to talk and we learned to listen...
Post Reply

Return to “C++”