Threads Arrrggggghhhh!!!!

R

raican

I've written a module for a larger project which can dynamically
created and free up to 16 threads and has an extra thread which watches
the treads to see when they terminate (this runs always, and cannot be
paused). all this works superbly!

then i added pause (suspend) and resume functionality, and this works
for the most part...

having all 17 threads running (16 dynamic and 1 watcher) the cpu usage
runs happily around 0-4% to 10-12%. when they are all paused, cpu usage
is around the same. then when they are all resumed, cpu usage again
remains the same. when individual threads are paused and resumed, the
cpu is quite happy.

then the problems arise. if you have any number of paused threads, and
then create a new thread, the cpu usage jumps to 100%.

needless to say my processor fan goes in to overdrive, and sounds like
a jet engine.

even when the newest thread terminates, the cpu stays at 100%. the cpu
only returns to normal if all the paused threads are resumed, or if
they are all freed.

i am pretty confident it is not the watcher thread, as i have disabled
it in code, and the cpu still goes crazy. i also don't believe it is
the dynamic threads, as, like i said earlier, the cpu stays at 100%
even when the new thread terminates.

Any ideas? Any Clues?

Could it be on of the other threads in the program, i.e. forms?
could it be on of the paused dynamic threads?
could it be another process entirely?

Arrrgggghhhhh!!!!!!

Is there anyway to monitor the threads, and see which one is eating the
cpu time.

I've tried the Process Class with Process.GetProcesses() and
Process.Threads, but all i can get is the Thread IDs not the Names, so
i don't know which is which...

Help me Obi Wan... I've been at this three days, and i only had 4 hours
sleep last night.


Thx All.
 
J

John Timney \(ASP.NET MVP\)

what are your threads doing ?

Total guess here - If they are doing things like network connections/file
handles then they may be consuming more pool threads than are available and
stalling the processing of the paused threads, adding to the pool then means
the machine goes mad trying to add more to the pool and it causes queing.
Take your logic out of the threads so they do nothing except run and pause
and see if the problem remains.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
 
R

raican

Thanks for getting back John, certainly something to think about, but
according to the Windows Task Manager, there are only approx 23 threads
running when all the dynamic threads are running. that'd be the 16
dynamic and the watcher, and 6 for the rest of the program.

as for network connections, the threads will be used for that
eventually, but at the moment all they do is throw an event saying how
many times they have iterated.

i.e.

while(ThreadRunning)
{
for(int i = 0; i < 100; i++)
{
ThrowText("Thread " +
Thread.GetCurrentThread.Name +
" has iterated " +
i.ToString() +
" times."

Thread.Sleep(1000);
}
}

Any other thoughts, i'm really quite baffled :(

Thanks in advance to anyone wishing to help...
 
R

raican

Due to the nature of the project i'm working on, i can't post any of
the code i'm working on. sorry, jon. but any ideas would be
appreciated. :)
 
J

Jon Skeet [C# MVP]

raican said:
Due to the nature of the project i'm working on, i can't post any of
the code i'm working on. sorry, jon. but any ideas would be
appreciated. :)

You don't have to post your actual code - just come up with a short but
complete program which demonstrates the problem. It won't need to do
*anything* business-specific.
 
J

John Timney \(ASP.NET MVP\)

we wont steal it - honest..............lol

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
 
G

Guest

Hi,
Any luck on this issue ?
I am interested to know what caused this.
Please post your findings when you get a chance.
romy
 

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

Top