J
Jesper Rasmussen
Hi,
Im sure this must be a FAQ, or a known issue, but i
haven't been able to find any information on it.
When I have one thread suspended and another one starts
running, the CPU jumps to 100% untill the thread is
resumed! this can't be appropriate behaviour?
See example code and output below!
Thanks in advance for any input
Jesper Rasmussen
(please cc email if possible)
------------------------------------------
Example:
------------------------------------------
class Class1
{
public static void thread1()
{
while(true)
{
Console.WriteLine("T1");
Thread.Sleep(1000);
}
}
public static void thread2()
{
while(true)
{
Console.WriteLine("
T2");
Thread.Sleep(1000);
}
}
private static Thread t1;
private static Thread t2;
static void Main(string[] args)
{
t1 = new Thread(new ThreadStart
(thread1));
t1.Start();
Thread.Sleep(3000);
Console.WriteLine("Suspending
T1");
t1.Suspend();
Thread.Sleep(2000);
t2 = new Thread(new ThreadStart
(thread2));
t2.Start();
Thread.Sleep(3000);
Console.WriteLine("Suspending
T2");
t2.Suspend();
t1.Resume();
Thread.Sleep(3000);
Console.WriteLine("Test Done");
t2.Resume();
}
}
-------------------------------------------
Output:
-------------------------------------------
T1 <5%cpu
T1 <5%cpu
T1 <5%cpu
Suspending T1 <5%cpu (for the 2 secs until T2 starts)
T2 100%cpu
T2 100%cpu
T2 100%cpu
T2 100%cpu
Suspending T2
100%cpu (still 100% when both is suspended)
T1 <5%cpu (T1 resumed)
T1 <5%cpu
T1 <5%cpu
Test Done
Im sure this must be a FAQ, or a known issue, but i
haven't been able to find any information on it.
When I have one thread suspended and another one starts
running, the CPU jumps to 100% untill the thread is
resumed! this can't be appropriate behaviour?
See example code and output below!
Thanks in advance for any input
Jesper Rasmussen
(please cc email if possible)
------------------------------------------
Example:
------------------------------------------
class Class1
{
public static void thread1()
{
while(true)
{
Console.WriteLine("T1");
Thread.Sleep(1000);
}
}
public static void thread2()
{
while(true)
{
Console.WriteLine("
T2");
Thread.Sleep(1000);
}
}
private static Thread t1;
private static Thread t2;
static void Main(string[] args)
{
t1 = new Thread(new ThreadStart
(thread1));
t1.Start();
Thread.Sleep(3000);
Console.WriteLine("Suspending
T1");
t1.Suspend();
Thread.Sleep(2000);
t2 = new Thread(new ThreadStart
(thread2));
t2.Start();
Thread.Sleep(3000);
Console.WriteLine("Suspending
T2");
t2.Suspend();
t1.Resume();
Thread.Sleep(3000);
Console.WriteLine("Test Done");
t2.Resume();
}
}
-------------------------------------------
Output:
-------------------------------------------
T1 <5%cpu
T1 <5%cpu
T1 <5%cpu
Suspending T1 <5%cpu (for the 2 secs until T2 starts)
T2 100%cpu
T2 100%cpu
T2 100%cpu
T2 100%cpu
Suspending T2
100%cpu (still 100% when both is suspended)
T1 <5%cpu (T1 resumed)
T1 <5%cpu
T1 <5%cpu
Test Done