J
Johan Karlsson
Hi!
First of all, I didn't find a Threading newsgroup that I would figure this
post to belong to, and its not languagespecific so I hope this is the right
group.
Anyhow, consider the following:
You have a collection called A that is inherited from collectionbase. You
implement the Add and Remove method something like this:
Public Sub Add (byref addItem as SomeObject)
SyncLock me
list.add( addItem )
End SyncLock
End Sub
(And remove kinda the same way).
Two questions:
1) If the Add failes, what happens with the lock. Do I need to wrap this in
a try finally block?
2) If another thread is enumerating this collection, what happens when the
lock kicks in?
My dream scenario:
* Not to do anything to the code that read and enumerates the collection.
Basicaly read the collection with a for each statement knowing that its
threadsafe due to the next point.
* Only to add the synclock in the enumerations Add and Remove (and perhaps
Clear is I'll allow that to happen).
Am I dreaming or is this going to work?
Thanks
/Johan
First of all, I didn't find a Threading newsgroup that I would figure this
post to belong to, and its not languagespecific so I hope this is the right
group.
Anyhow, consider the following:
You have a collection called A that is inherited from collectionbase. You
implement the Add and Remove method something like this:
Public Sub Add (byref addItem as SomeObject)
SyncLock me
list.add( addItem )
End SyncLock
End Sub
(And remove kinda the same way).
Two questions:
1) If the Add failes, what happens with the lock. Do I need to wrap this in
a try finally block?
2) If another thread is enumerating this collection, what happens when the
lock kicks in?
My dream scenario:
* Not to do anything to the code that read and enumerates the collection.
Basicaly read the collection with a for each statement knowing that its
threadsafe due to the next point.
* Only to add the synclock in the enumerations Add and Remove (and perhaps
Clear is I'll allow that to happen).
Am I dreaming or is this going to work?
Thanks
/Johan