-
Notifications
You must be signed in to change notification settings - Fork 0
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
Extend the concept of async-init to cover asynchronous monitors #1
Comments
Imagine something like this:
Doing so automatically adds mutual exclusion between It's possible that the class itself requires a decorator to setup the utilities for mutual synchronisation, similar to how the async init class decorator is needed before method decorators. |
It's like a macro, use it with great power and great responsibility. |
A deadlock detection works by having a shared context. In this case the shared context can be maintained by the Specifically the shared context requires is the call-stack itself. That is when calling The method decorators can made invisible book-keeping attached to the call-stack? The only way to bookkeep certain state relative to the callstack is to attach as a parameter. This makes it a little bit complicated since we basically need a Now it may not be a huge issue, if the That being said, we did create decorators in Only then can you "thread" a locking bookkeeper that knows what locks were locked in that call context. Even then this isn't foolproof because, if a method calls the other method transitively, it can forget to propagate this context. I think a robust solution eventually somehow meta-program JS so you can get access to the meta callstack. Perhaps using something like: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/caller to get a reference to locking bookkeeper. Also see this MatrixAI/js-db#39 for general discussion about deadlock detection when you do have a context object (like in the case of Note that in the case of |
This is now done in https://github.com/MatrixAI/js-async-monitor |
I'm moving this there, and will close it there. |
I'm going to release this as 0.0.1 because this is mostly an experiment. There are still issues like the fact that there's no automatic deadlock detection which makes this utility a bit of a footgun. |
Ok this will be released in https://gitlab.com/MatrixAI/open-source/js-async-monitor/-/pipelines/888748266 |
Is your feature request related to a problem? Please describe.
Basically our usage of class decorators and method decorators for managing the asynchronous initialisation of classes is basically an implementation of the CS concept "monitor".
However the usage of locking right now only applies to asynchronous construction and asynchronous destruction.
We could generalise this library for arbitrary concurrent synchronisation, and call it
js-async-monitors
.Describe the solution you'd like
Make it possible to use decorators to indicate arbitrary synchronisation requirements on class methods. I suspect that an extra decorator will be needed beyond class and method/member decorators. Probably something like function decorators, or just "hooks" similar to react hooks, that allow arbitrary synchronisation based on conditions.
It can make use of the
Barrier
that was recently introduced injs-async-locks
.Describe alternatives you've considered
Introducing more concurrent synchronisation can introduce subtle deadlocks. Programming models may give the possibility to break things. Better abstractions can help prevent mistakes, and I'm not sure if introducing more locking is the best solution.
At any case, a deadlock detection system should be in place to prevent races.
Additional context
The text was updated successfully, but these errors were encountered: