|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Thread synchronization.I am hoping that someone can help me understand how to use Synclock properly. I am a tad confused. I have a class that is instanced on multple threadpool threads, and uses shared members to track the state shared by all instances. The web is littered with examples of people using ... Synclock GetType(MyClass) ' Do something to shared class members. End Synclock .... to access static members when many threads may own instances of the class. I understand that is dangerous because the type object may be locked from outside the object causing deadlocks, and I am led to believe that a private locking object is the way to go. So should I do something like this; Private Shared _lockObject As Object .... Synclock _lockObject ' Do something to shared class members. End Synclock Or should I be locking on a type rather than an instance? Thanks. Blake wrote:
Show quoteHide quote > Heya Group. One correction, make sure initialize the instance :)> > I am hoping that someone can help me understand how to use Synclock > properly. I am a tad confused. I have a class that is instanced on > multple threadpool threads, and uses shared members to track the state > shared by all instances. > > The web is littered with examples of people using ... > > Synclock GetType(MyClass) > ' Do something to shared class members. > End Synclock > > ... to access static members when many threads may own instances of the > class. > > I understand that is dangerous because the type object may be locked > from outside the object causing deadlocks, and I am led to believe that > a private locking object is the way to go. > > So should I do something like this; > Private Shared _lockObject As New Object ^^^^ > ... Look on a private shared object that you create (your second exampl) -> Synclock _lockObject > ' Do something to shared class members. > End Synclock > > Or should I be locking on a type rather than an instance? > > Thanks. never lock on the type. That is a result of some bad MSDN examples... -- Tom Shelton
How to get app.config info from code in a referenced class
VB.NET and MDAC+JET update access mdb VB 2005 and Windows vista Strange but true ... im at a loss help !!! question about inheritance and Imports statement XML over TCP directing output to selected monitor in a multi-monitor desktop calling a .bat program in a vb .net program It's impossible to debug code in MyApplication_UnhandledException |
|||||||||||||||||||||||