Repository: Rust-SDL2/rust-sdl2 (language: rust)

Issue:
Is event pump thread safe?
The documentation says: `A thread-safe type that encapsulates SDL event-pumping functions.`. But then, `EventPump` is `!Send` and `!Sync`. So either the documentation is wrong, or the implementation regressed.


Discussion / hints:
I'll have to check it out later, but I think it's on purpose (that it's `!Sync` and `!Send`). I remember seeing some discussion over this on github a few years ago, I'll try to have a look soon.
Got it: https://wiki.libsdl.org/SDL_PumpEvents

> WARNING: This should only be run in the thread that initialized the video subsystem, and for extra safety, you should consider only doing those things on the main thread in any case.

And the struct `EventPoll` uses an `Rc<_>` specifically to prevent struct from being sent to another thread.

Hence it's a doc issue.
The EventPump is not, but however sending an Event?. You could collect the event data yourself into a HashSet or HashMap to get this to work. Though, sending the Event itself should a better solution.
https://github.com/Rust-SDL2/rust-sdl2/pull/838


Fix patch:
diff --git a/src/sdl2/sdl.rs b/src/sdl2/sdl.rs
index dc8f781c93..44bd2dfa3c 100644
--- a/src/sdl2/sdl.rs
+++ b/src/sdl2/sdl.rs
@@ -329,7 +329,7 @@ subsystem!(SensorSubsystem, sys::SDL_INIT_SENSOR, SENSOR_COUNT, sync);
 
 static IS_EVENT_PUMP_ALIVE: AtomicBool = AtomicBool::new(false);
 
-/// A thread-safe type that encapsulates SDL event-pumping functions.
+/// A type that encapsulates SDL event-pumping functions.
 pub struct EventPump {
     _event_subsystem: EventSubsystem,
 }


Test patch: