I have a multitheaded app. in wich I do not user AutoResetEvent for handling
classes that are common for all threads.
now, I have a procedure in a common class that looks like this:
Public Sub aa(byref Object1 as cObject)
synclock Objekt2
//radi nesto sa objektom 1
end synclock
end sub
But, is it possible that because there's no AutoResetEvent, that one thread
enters SyncLock block, and during that period another thread enters Sub, and
made changes in reference to Object1 causing wrong data in 1st thread?
> [...]
> But, is it possible that because there's no AutoResetEvent, that one
> thread
> enters SyncLock block, and during that period another thread enters Sub,
> and
> made changes in reference to Object1 causing wrong data in 1st thread?
The lack of an AutoResetEvent isn't a problem per se, but yes...
You need to synchronize access to _any_ data that could be accessed
simultaneously by different threads. If one thread may be trying to use
Object1 at the same time that another thread is, that's potentially a
problem.
In your example, if you could ensure that any time access to Object2 is
synchronized, access to Object1 is also synchronized, that would be fine.
For example, only ever using Object1 from within a lock on Object2.
Beware of locking on _both_ Object1 and Object2 independently, as this is
a good way to create a deadlock situation.
Pete