Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async locking #130

Open
hazzik opened this issue Jun 20, 2019 · 1 comment
Open

Async locking #130

hazzik opened this issue Jun 20, 2019 · 1 comment

Comments

@hazzik
Copy link
Contributor

hazzik commented Jun 20, 2019

@maca88 nhibernate/nhibernate-core#2147 (comment) :

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:

  1. If there are several methods with [MethodImpl(Synchronized)] in a class the generator shall generate only one locker fields for all these methods.

  2. (Optional) The locker should pass the current lock object to the async lock. (MethodImplOptions.Synchronized is actually equivalent to lock(GetType())/lock(this))

@maca88
Copy link
Owner

maca88 commented Jun 20, 2019

  1. I do agree.

  2. 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 MethodImpl attribute and lock statement. Leaving this as optional, maybe, but I don't think this should be set by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants