d-unsed / ruru

Native Ruby extensions written in Rust
MIT License
832 stars 40 forks source link

worker thread cleanup and `Drop` #100

Open jstrong-tios opened 5 years ago

jstrong-tios commented 5 years ago

I haven't been able to find any documentation about how worker threads which don't interact directly with ruby objects are handled in terms of Drop. In my case I have existing rust code which establishes a long-running thread worker to handle incoming "jobs" via a channel. The thread "lives" in a struct that implements Drop, which tells the thread to stop waiting for new messages and terminate when it's dropped (glossing over details here). In this case, my expectation is the rust/ruru interface to ruby can cleanly send data (perhaps copied data) from ruby over the channel to the thread worker. Would the thread worker need to be setup with the Thread struct in ruru (Thread::call_without_gvl)? Or could I use std::thread? Will Drop be called when the parent struct is destroyed?

Thanks for any help you can provide.