Click here to Skip to main content
15,898,597 members
Home / Discussions / C#
   

C#

 
GeneralRe: string array Pin
Martin#26-Jul-07 23:17
Martin#26-Jul-07 23:17 
GeneralRe: string array Pin
Xmen Real 27-Jul-07 2:22
professional Xmen Real 27-Jul-07 2:22 
GeneralRe: string array Pin
Martin#27-Jul-07 3:25
Martin#27-Jul-07 3:25 
GeneralRe: string array Pin
Xmen Real 27-Jul-07 4:48
professional Xmen Real 27-Jul-07 4:48 
GeneralRe: string array Pin
Martin#27-Jul-07 9:28
Martin#27-Jul-07 9:28 
GeneralRe: string array Pin
Xmen Real 27-Jul-07 18:07
professional Xmen Real 27-Jul-07 18:07 
GeneralRe: string array Pin
Martin#29-Jul-07 8:59
Martin#29-Jul-07 8:59 
QuestionHow to increment the value of "Current Queue Length" counter for .NET CLR LocksandThreads Pin
Vikas Pai26-Jul-07 20:35
Vikas Pai26-Jul-07 20:35 
Hello,
I am stuck up with one problem from last 4 days please help.

Problem: I have to write a code to simulate DEADLOCK among threads and the formula that is documented for detecting the deadlock is:
Formula: “Current Queue Length” = “Threads Count” AND “Process/% Processor Time” < 1

The Definition of “Current Queue Length” counter is
: This displays the total number of threads that are currently waiting to acquire a managed lock in the application.Iit displays the last observed value. This helps you identify inefficient synchronization mechanisms.
The count keeps on rising steadily.

But this Counter(Current Queue Length) always shows 0 value when I look at it's value through Perfmon utility

The code which I have written is as follows:

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace Threads
{
class Tester

{
static void Main( )
{
// make an instance of this class
Threads.ThreadingExamples.CPUSpinWithDeadlock p = new Threads.ThreadingExamples.CPUSpinWithDeadlock();

// run outside static Main
p.DoTest();
break;
}

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.IO;

namespace Threads.ThreadingExamples
{
class CPUSpinWithDeadlock
{
public bool locked = true;
public static Thread[] ThreadsArray = new Thread[10];

//Creating a var "Count" which should be in Critical Section to avoid concurrent access to it.
public static string Count = "You r in ";

public void DoTest()
{
Console.WriteLine("Press any key to continue");
Console.Read();
//Main Thread ------- Starts.

//Lock the var Count to avoid concurrent access by threads.

for (int counter = 0; counter < 10; counter++)
{
if (counter == 0)
{
ThreadsArray[counter] = new Thread(
new ThreadStart(ILoop));
}
else
{
ThreadsArray[counter] = new Thread(
new ThreadStart(Loop));
}
ThreadsArray[counter].Start();
}
}

public void ILoop()
{
Console.Write("First Thread ");

Lock(CPUSpinWithDeadlock.Count)
{
Count = "Main Thread";
while (true)
{
Console.WriteLine("Hello");

//Thread Sleep to reduce the CPU Utilization by current thread.
Thread.Sleep(1000);
}
}
}

public void Loop()
{
Console.Write("Calling lock ");

// To make remaining 9 threads wait for thread no 1 to release the lock acquired by it
//so that the remaining threads would be queued and the the counter value of "Current Queue Length"
// would go up.

CPUSpinWithDeadlock.ThreadsArray[0].Join();

Lock(CPUSpinWithDeadlock.Count)
{
CPUSpinWithDeadlock.Count = "Child Thread";
Monitor.Exit(CPUSpinWithDeadlock.Count);
}

}
}
}




Thanks & Regards,
Vikas M Pai
Software Engineer
QuestionDefault Parameters Pin
M. J. Jaya Chitra26-Jul-07 20:17
M. J. Jaya Chitra26-Jul-07 20:17 
AnswerRe: Default Parameters Pin
Christian Graus26-Jul-07 20:22
protectorChristian Graus26-Jul-07 20:22 
GeneralRe: Default Parameters Pin
M. J. Jaya Chitra26-Jul-07 21:03
M. J. Jaya Chitra26-Jul-07 21:03 
GeneralRe: Default Parameters Pin
Michael Sync26-Jul-07 21:29
Michael Sync26-Jul-07 21:29 
QuestionMarshallByreference Pin
prabhu dot net26-Jul-07 19:55
prabhu dot net26-Jul-07 19:55 
QuestionCrystal report Problem Pin
help as an alias26-Jul-07 19:46
help as an alias26-Jul-07 19:46 
AnswerSTOP !!! Pin
Christian Graus26-Jul-07 20:21
protectorChristian Graus26-Jul-07 20:21 
AnswerRe: Crystal report Problem Pin
T.EDY26-Jul-07 20:48
T.EDY26-Jul-07 20:48 
Questionload file names Pin
amilapradeep26-Jul-07 18:43
amilapradeep26-Jul-07 18:43 
AnswerRe: load file names Pin
Christian Graus26-Jul-07 18:47
protectorChristian Graus26-Jul-07 18:47 
GeneralRe: load file names Pin
amilapradeep26-Jul-07 19:17
amilapradeep26-Jul-07 19:17 
QuestionCapturing the Current Line of Text from RichTextBox [modified] Pin
bneacetp26-Jul-07 17:33
bneacetp26-Jul-07 17:33 
AnswerRe: Capturing the Current Line of Text from RichTextBox Pin
Abisodun27-Jul-07 2:23
Abisodun27-Jul-07 2:23 
QuestionRe: Capturing the Current Line of Text from RichTextBox Pin
bneacetp27-Jul-07 15:02
bneacetp27-Jul-07 15:02 
AnswerRe: Capturing the Current Line of Text from RichTextBox Pin
Abisodun28-Jul-07 3:54
Abisodun28-Jul-07 3:54 
QuestionHow to know if a DataTable has been created? Pin
Khoramdin26-Jul-07 12:59
Khoramdin26-Jul-07 12:59 
AnswerRe: How to know if a DataTable has been created? Pin
Christian Graus26-Jul-07 13:52
protectorChristian Graus26-Jul-07 13:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.