SyncLock question.

J

Joel Denton

I have a question about when synclock is necessary. Most of the
examples I've seen have suggested synclocking on a static/shared
object for synchronizing access to class data. What I'm not clear on,
is when it is needed.

For example...

Public Class MyClass
Dim i as Integer

Public Sub DoIt()
...Do something to mod the private i var
End Sub
End Class

For iCnt = 1 to 10
Dim obj as New MyClass
Dim oThread As New Thread(AddressOf obj.DoIt)
oThread.Start()
Next

Each new thread has it's own instance of MyClass, and the DoIt sub is
only using private members and vars. Is there any need to synclock in
this case? I understand locking if all 10 threads shared the same
instance of MyClass, but I'm not clear as to whether it is required
for different instances.

Thanks,
Joel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top