Ok, I have a huge program and I ran it today and found that its using 100% of the CPU and bogging down the system to such a degree moving the mouse is an effort - let alone opening a window.

I've been trying all day to narrow down the problem, mainly by putting sleeps in threads to see if that effects the usage , hoping to find the offending thread. or commenting out sections of code to see what happens. Needless to say, its not worked at all.

I only noticed the problem a couple of hours ago, but changing the things I did hasn't affected it at all, I'm completley lost as to what to do next, any ideas?

Have you tried running the program via a debugger?

yes, what would specific actions would help using the debugger?

yes, what would specific actions would help using the debugger?

You can set break points in your executing process, allowing you to examine where(and why) your process runs away with all the processing power.

You can set break points in your executing process, allowing you to examine where(and why) your process runs away with all the processing power.

I've tried.. It hasn't really helped narrow down the problem - Whichever thread I put the breakpoint in, stops all threads. Ive got three different threads, two of which are active and I think causing the problem - If I stop in one, the other stops too, and of course the CPU usage drops instantly. I can't narrow down where in either thread the cause of the problem is by breaking in it, because that just stops the CPU being used... if you get what I mean?

edit - just commented out all the code in both threads (after it was used to get everything working) and its still jerking everything up, so it must be something in a different thread that I didn't do... gonna be fun finding this

100% CPU usage is common with SpinWait cycles (where you sit in a loop waiting for something to flag or a number of iterations)

Other than that, it would be an action you've asked it to perform asynchronously (may not be a part of your code)

If stopping one thread stops both, I imagine you have them Mutex'd together and the second thread is waiting for the one you paused?

When you hit a breakpoint, it only stops the thread that hits that breakpoint (until another thread hits the breakpoint)

So if you have two threads, ThreadOne and ThreadTwo. ThreadOne runs the "DoWorkOne()" and ThreadTwo runs "DoWorkTwo()" and you set a breakpoint in "DoWorkOne()" only ThreadOne would stop. ThreadTwo should continue to run unless it is Waiting on ThreadOne (via mutex/semaphore/spinwait etc.)

Based on what you're saying, it sounds like you have a SpinWait going off somewhere or a tight loop setting off threads like mad.
(100% CPU is also a symptom of exceeding the thread-pool thresh-hold)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.