New `synchronized`
Posted: Sun Sep 01, 2013 2:52 am
In general, .NET enables an entire method to be synchronized/locked with the MethodImpl attribute:
Not very attractive, is it? I have added some syntactic sugar for this:
The block-level equivalent is the lock statement which makes me wonder if we should say "is locked" instead for consistency:
Also, in C# discussions on using the attribute vs. the lock() statement around the entire method body, there seems to be some confusion as to whether or not using the attribute is acceptable. If we find out it's not, the Cobra implementation for "is synchronized" or "is locked" would be changed to generate the lock statement around the method body.
Or maybe this feature is a bad idea because "the body of a lock should do as little as possible" and it may encourage the opposite.
Opinions?
P.S. You can browse tests cases here if you're interested to see them.
use System.Runtime.CompilerServices
class X
def foo has MethodImpl(MethodImplOptions.Synchronized)
# do some stuff
Not very attractive, is it? I have added some syntactic sugar for this:
class X
def foo is synchronized
# do some stuff
The block-level equivalent is the lock statement which makes me wonder if we should say "is locked" instead for consistency:
class X
def foo is locked
# do some stuff
Also, in C# discussions on using the attribute vs. the lock() statement around the entire method body, there seems to be some confusion as to whether or not using the attribute is acceptable. If we find out it's not, the Cobra implementation for "is synchronized" or "is locked" would be changed to generate the lock statement around the method body.
Or maybe this feature is a bad idea because "the body of a lock should do as little as possible" and it may encourage the opposite.
Opinions?
P.S. You can browse tests cases here if you're interested to see them.