Callback system #263
-
Hi again, I'm still somewhat stuck on an issue I raised before, which was helpfully answered, but I've hit another roadblock. I'm wanting to develop a plugin system which is asynchronous. I'm taking a NodeJS approach here by handling callbacks. Issue is I seem to be running into threading issues. struct Plugin {
lua: Arc<rlua::Lua>
}
impl Plugin {
fn new() {
Arc::clone(&self.lua).context(|ctx| {
let lua = Arc::clone(&self.lua);
ctx.globals().set("do_async_operation", ctx.create_function(|_, (callback,): (rlua::Function,)| {
lua.context(|ctx| callback.call(()).unwrap());
}
}).unwrap());
}
} do_async_operation(function ()
print("[Lua] Async Operation Successful")
end) But I seem to be getting thread-safety errors:
To summarise:
Any pointers would be much appreciated |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi,
If you do want to share between threads (or use APIs which assume you might need to), then you probably want Chris |
Beta Was this translation helpful? Give feedback.
Hi,
It would be useful to see which lines are causing the error messages, but, thinking aloud:
Arc<Lua>
probably isn't what you want;Lua
isn'tSync
(i.e. it can't be shared between threads) so even if you sent theArc<Lua>
to another thread you wouldn't be allowed to use it. If you want to stay on one thread, I would useRc<Lua>
instead (or justLua
if you don't need to share it).If you do want to share between threads (or use APIs which assume you might need to), then you probably want
Arc<Mutex<Lua>>
.Chris