Closed Schoonology closed 6 years ago
I apologize for submitting a PR without first discussing the changes in an issue, and I know this seems like a duplicate of #44. The difference with this Pull Request is that it's far more wide-reaching, yet it does a better job of guaranteeing safety in the face of state changes going on within termbox
.
I need this change for an application I'm building in an effort to render updates constantly while allowing user input. The other alternative I considered was splitting the master RustBox
container into an input half and a rendering half, but the same thread safety work would be guaranteed to prevent multiple writes to the underlying termbox
state.
I think changing Rustbox's external API to be mutable is something we want to avoid. See this comment for an explanation as to why we should maintain Rustbox's interior mutability.
@gchp I think we can safely close this, as it's addressed by #81.
Thanks @Schoonology for the work here. This is addressed in a different way in #81. Let me know if you have any other thoughts/issues! And thanks @jmacdonald for the patch.
@gchp My pleasure!
The effects are twofold:
!Send
PhantomData
element fromRustBox
, allowing aRustBox
container to be shared between threads.termbox
state will be changed. This requires all sharedRustBox
instances to be wrapped in anArc<Mutex<>>
.Additionally, a "thread-safety" example was added.