[Mono-devel-list] [PATCH] Warn on lock (string) or lock(typeof (Foo))

Kornél Pál kornelpal at hotmail.com
Fri May 27 18:46:21 EDT 2005


> Good idea overall, though I'd suggest a slight change warn whenever you
> lock on a public member.  This would catch both System.Type and string
> (both are public members), and it's generally not safe to lock on public
> members for the same reasons locking on string or System.Type is unsafe
> (increased possibility for deadlock being the primary issue).

I think locking on public members is not unsafe. For example locking on
SyncRoot (where applicable) is good as it will sychronize the operation
accross all its wrapper methods.

And never forget that if someone wants to cause deadlock (or do other evil
things) he can do it using Reflection as well as anyone
(ReflectionPermission is rarely revoked) can read and even write private
members.

Kornél




More information about the Mono-devel-list mailing list