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

Allow for "reentrant" callbacks #1871

Open
gdamore opened this issue Sep 10, 2024 · 0 comments
Open

Allow for "reentrant" callbacks #1871

gdamore opened this issue Sep 10, 2024 · 0 comments

Comments

@gdamore
Copy link
Contributor

gdamore commented Sep 10, 2024

Right now we require that callbacks be completed on a different thread in order to resolve issues that can arise when the callback cannot be executed on the same thread as the submitter. For example, the submitting thread might be holding a lock that the callback will need to acquire to perform it's job. That would result in a deadlock, and as a safeguard we have ensured that the callback is always executed on a separate thread. Sometimes we could avoid this. Some thoughts:

a) Allow consumers to register a "reentrant" version of the callback or indicate that the callback is reentrant. This may require some extra signaling to the callback to indicate when the thread is the same as the submitter. This could be passed in via a function argument, a flag in the aio, or simply by requiring the calling thread to check the thread id. The last of this is probably the least desirable from a usability standpoint.

b) If we keep track of the thread id, we could also then recognize when the submitting thread differs from the thread calling nni_aio_finish, and complete it synchronously.

c) We could combine both a & c, meaning that asynchronous completions should indeed become rather uncommon. This is likely to have a dramatic impact on the average latency and scalability of NNG.

And none of this needs to be particularly difficult or risky to implement.

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

No branches or pull requests

1 participant