I guess I got problems with deadlock...My program is working well but some time it get unresponsive...???. In source code (C#)..have no lock(objet) or ReaderWriterLockSlim... I did try to reproduce the deadlock with 2 threads using same object (List) but no success..
int n = 0;
List<int> temp = new List<int>();
var up = new Thread(() =>{
for (int i = 0; i < 100000; i++){
n++;
temp.Add(i);
}
});
var down = new Thread(() => {
for (int i = 0; i < 100000; i++){
n--;
try{
temp.Remove(i);
}catch {
Console.WriteLine("No item {0} to remove", i);
}
}
});
up.Start();
down.Start();
down.Join();
up.Join();
Console.WriteLine(String.Join(",",temp));
The snipe code above still works without deadlock..??? Could someone help me to reproduce the deadlock with 2 threads using same variable without lock(object) or System lock...
Thank in Advance