Async locking
@maca88 https://github.com/nhibernate/nhibernate-core/pull/2147#issue-275171711 :
Currently, the async generator is generating separate fields for lock statements that contain an async invocation, which may cause troubles as two threads may simultaneously execute the same code, one for async and one in sync version of the method.
I think the rules should be like following:
-
If there are several methods with
[MethodImpl(Synchronized)]in a class the generator shall generate only one locker fields for all these methods. -
(Optional) The locker should pass the current lock object to the async lock. (
MethodImplOptions.Synchronizedis actually equivalent tolock(GetType())/lock(this))
-
I do agree.
-
The problem with async locking is that all implementations that I am aware of do not support to pass a lock object which would be used to lock a thread. By not having such async locking, it is not possible to achieve blocking different threads from executing the same code, which can lead to various bugs that are hard to debug. Allowing such behavior doesn't seem right to me and that is why my plan was to remove support for
MethodImplattribute andlockstatement. Leaving this as optional, maybe, but I don't think this should be set by default.