Re: Class and Multi-thread safety



Nuno Magalhaes <nunommagalhaes@xxxxxxxxxxx> wrote:
What is the difference between locking on "this" and locking on an
object inside the class? My object is never changed. What can go wrong?

Someone else can acquire a lock on it, inadvertently blocking things at
the wrong time. The more control you can exercise over what lock is
taken out when, the fewer deadlock risks you'll have.

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.



Relevant Pages

  • Re: Filibustering
    ... >>>You implied it when replying to a thread where I had stated I wanted ... >>You might have forgotten to lock it. ... Alex Heney, Global Villager ...
    (uk.legal)
  • Re: Filibustering
    ... >>You implied it when replying to a thread where I had stated I wanted ... >You might have forgotten to lock it. ... >Or (if he is your daughters boyfriend) she might have lent him a key. ...
    (uk.legal)
  • Re: Subroutine lock doesnt work for me. Please help
    ... Thanks for replying, and yes, adding the variable does help. ... you a few more questions or whoever: ... Why the need to add the $lock variable since doesn't the subroutine ... (and since section on subroutine lock ...
    (comp.lang.perl.misc)
  • Re: Thread Locking In Static Methods - How?
    ... >> public static void LogText ... >> lock ) ... > Both lockand lock) are a bad idea, IMO. ... > If replying to the group, please do not mail me too ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: lock(...) question
    ... Two thread wants to get an instance of your singleton class. ... > time another thread has came and second one also wants to lock. ... After first thread releases m_syncRoot. ... If replying to the group, please do not mail me too ...
    (microsoft.public.dotnet.framework)