Jasper Kent <ja*********@hotmail.com> wrote:
lock can be applied to any reference object (i.e. to objects of classes, not
of structs). The simplest way to use it is usually lock (this).
I would strongly recommend *not* locking on this. Instead, lock on a
private reference which *only* the class itself can see; you can also
have various locks for if you want to lock in different circumstances
(for instance, lock all method calls to A against each other, and all
method calls to B against each other, but you can have one of each of A
and B running at the same time). This way you can make the lock
variable name descriptive of *exactly* its purpose, and because no
other code will have a reference to what you're locking, they can't end
up locking on the same thing and causing problems.
In the rare occasions where you need multiple classes to lock on the
same reference, again I'd suggest creating a separate object just for
the purpose of locking.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too