mlua-rs / mlua

High level Lua 5.4/5.3/5.2/5.1 (including LuaJIT) and Roblox Luau bindings to Rust with async/await support
Other
1.72k stars 137 forks source link

Send feature flag #411

Open lewisclark opened 5 months ago

lewisclark commented 5 months ago

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?

khvzak commented 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.

cppcoffee commented 4 months ago

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