mlua icon indicating copy to clipboard operation
mlua copied to clipboard

Send feature flag

Open lewisclark opened this issue 1 year ago • 2 comments

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?

lewisclark avatar Jun 04 '24 19:06 lewisclark

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.

khvzak avatar Jun 04 '24 23:06 khvzak

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>>,
}

cppcoffee avatar Jun 07 '24 04:06 cppcoffee

v0.10 has proper support of Send+Sync

khvzak avatar Dec 01 '24 13:12 khvzak