-
-
Notifications
You must be signed in to change notification settings - Fork 137
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
(0.10-beta) send+module: invoking lua functions from another thread #443
Comments
Unfortunately One of possible solution can be using channels for communicating between threads and invoking callback when a value is present in the channel (checking periodically). |
Thanks for your reply, sorry for taking a while to get back at you! I think it could be possible to handle the state mutex "the other way around": acquiring it when leaving module code and releasing it as soon as we enter module code (basically as first step of every mlua function). This would still mean that the main Lua thread needs to yield from time to time but it can either be done manually or periodically with a In the meantime I'm doing as you suggest: keeping a global static channel where i send my However, since You can check our project for context: build with Would you be open to either drop this restriction or allow something like |
i'm developing a nvim plugin which is mostly a thin wrapper around a native library. such library works in background and wants to invoke callbacks to do arbitrary work on-demand for new events.
a minimal example of my use case:
in addition to this, nvim exposes a lua interface to libuv's async handle, which is safe to invoke across threads and will wake the main loop thread to run the wrapped function
with this setup the callback given to the foreign thread should only interact with the async handle, which should be threadsafe. however after requiring the native module neovim will consistently crash after not many invocations.
since this is the new beta built this may be a temporary or already known bug, so feel free to close.
also i'm not sure this is supported use at all, i see with the
send
feature enabled lua values hold a mutexed weak ref, but it's not clear to me how this mutex is handled when mlua is a moduleif my usage is unsupported, is it possible to clear the callback environment or run it in another context to call it safely? is it possible to lock the lua state and allow callbacks to execute safely from other threads?
anyhow, thanks for the wonderful library and your time, looking forward to mlua 0.10!
The text was updated successfully, but these errors were encountered: