lock used in thread and by event
- From: uupi_duu@xxxxxxxxx
- Date: Tue, 25 Sep 2007 04:04:04 -0700
Hello,
I have a application with two threads. I have also a resoure that is
synchronized by lock.
When testing locks before this App I noticed that if one threaded
application for test purposes
invokes code like below it does not start waiting.
lock(this)
{
..... some code
lock(this)
{
.... some code
} // Execution goes through both locks.
}
Okey for my two threaded Application. In main thread there is a
method that uses lock to protect a data structure. Code is like below:
class MyClass {
public void My Method(object item)
{
lock(_myList)
{
_myList.Remove(item);
}
}
.....
}
In same class there is also a eventhandler to remove items from List
and it's fired from another thread. Code is like below.
class MyClass {
public void OnRemoveItemFromList(object sender, ItemEventArgs e)
{
lock (_myList)
{
_myList.Remove(session)
}
}
......
}
From another thread List item is remove by Event like below:
class SecondThread {
.....
RemoveItemFromListEvent(this, new ItemEventArgs (this));
.....
}
What I have noticed that lock(_myList) does not stop and start waiting
if one of the threads have aquired it.
lock(_myList) goes allways through. So, can anyone explain that is
Event call same as a call executed in thread that owns lock(_myList)
or how this goes?
Can anyone clarify this to me?
Any documentation considering this issue?
Thanks!
.
- Follow-Ups:
- Re: lock used in thread and by event
- From: Jon Skeet [C# MVP]
- Re: lock used in thread and by event
- Prev by Date: Re: In service, use string to refer to array I should use?
- Next by Date: Re: date picker in mozilla
- Previous by thread: String matching with wildcards
- Next by thread: Re: lock used in thread and by event
- Index(es):
Relevant Pages
|
Loading