Friday, 15 March 2013

c# - lock(variable) - conflicting explanation of the variable -



c# - lock(variable) - conflicting explanation of the variable -

the docs don't explain it. should locked on , not.

from here seems same object should used threads lock work. while here seems that should avoided prevent deadlock.

keep in mind might misunderstanding whole matter of lock, because asked question how "lock" variable , got what seems me not accomplish @ (except locking code).

think of lock "talking stick" used in meetings. whoever holding stick can talk. wants talk must wait until speaker relinquishes stick.

when piece of code acquires lock on object, other piece of code requests lock on same object must wait until original code releases lock.

so object should lock? depends on context. rule of thumb lock object anyone else impact code block can lock well. if you're updating collection, can icollection.syncroot example.

edit op (hopefully correct): "anyone wants talk" - speaker "of stick". (anyone can talk.) sec link in question - it's referring problem of 1 lock waiting second, while sec waiting first.

c# .net multithreading

No comments:

Post a Comment