Open lewisclark opened 5 months ago
It adds Send
requirements to Rust functions and userdata objects, which is not always desirable. Also don't be confused with Sync
.
PS. Next mlua version will have send
feature flag replaced with sync
to allow easy integration with multithreading code.
Added the send
and async
features to Cargo.toml, then placed the Lua object into the BoxFeature. Compiler prompted an error:
*mut c_void cannot be shared between threads safely.
After reviewing the code, should we modify *mut c_void
to AtomicPtr
?
like:
pub struct LuaInner {
state: AtomicPtr<ffi::lua_State>,
// replace main_state: *mut ffi::lua_State,
main_state: AtomicPtr<ffi::lua_State>,
extra: Arc<UnsafeCell<ExtraData>>,
}
Is there anything I need to be careful of when using the
send
feature flag? It being locked behind a feature flag makes me wary that it has some side effects, as otherwise Send could be implemented by default?