jcmoyer / rust-lua53

Lua 5.3 bindings for Rust
MIT License
158 stars 45 forks source link

Implement `Send` for State. #45

Closed Parakleta closed 8 years ago

Parakleta commented 8 years ago

Since State properly manages the ownership of its contained pointer it should be made Send with unsafe impl Send for State {} so that once wrapped in a Mutex the Lua State can be shared between threads.

sagebind commented 8 years ago

I think your proposal is reasonable, since Lua states are thread-safe data; however, you still can't safely use a Lua state in more than one thread since mutating a state from more than one thread at a time causes undefined behavior.

Parakleta commented 8 years ago

Not using it simultaneously is handled by the Sync trait, which would not be applied. This just means that it needs to be wrapped in a Mutex. The problem is that without the Send trait the Mutex will not apply the Sync trait.