Repository: PistonDevelopers/glfw-rs (language: rust)

Issue:
Using `glfwPostEmptyEvent` to wake `glfwWaitEvents` is not possible
For creating an application which only refreshes when there is input, the use of `Glfw::wait_events()` is encouraged to avoid busy polling.

This function will suspend the thread until there are events to process.

The function `Glfw::post_empty_event` can be used to wake up the event processing thread in order to handle other events in the application, such as an internal refresh.

`wait_events` requires a mutable reference to `Glfw`, and `post_empty_event` requires a reference to Glfw. As such, it is not possible to wake up a thread suspended by `wait_events` through the use of `post_empty_event`, as Glfw is both mutably borrowed, non-send, and non-sync.

The docs mention that `post_empty_event`/`glfwPostEmptyEvent` is thread safe (which is the only way it could work`

https://www.glfw.org/docs/3.3/input_guide.html#events


Discussion / hints:
Reading this issue, I was confused, as I remember doing the exact thing that you're describing years ago. So I went digging. The change making this impossible was introduced in #473.

For now, the only alternative solution, is to manually call `glfwPostEmptyEvent()`, e.g.:

```rust
std::thread::spawn(|| {
    ...
    unsafe {
        glfw::ffi::glfwPostEmptyEvent();
    }
    ...
});
```





Fix patch:
diff --git a/src/lib.rs b/src/lib.rs
index ef80398e..4ee086ab 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1227,7 +1227,7 @@ impl Glfw {
     /// If no windows exist, this function returns immediately.
     ///
     /// Wrapper for `glfwPostEmptyEvent`.
-    pub fn post_empty_event(&mut self) {
+    pub fn post_empty_event() {
         unsafe {
             ffi::glfwPostEmptyEvent();
         }


Test patch: