What is the best way to prevent actions such as window-dragging from blocking the main thread?
I'd like to keep synchronous access to window properties such as location and size.
I have a working solution, but it doesn't seem thread-safe.
My solution consists of two threads:
- Creates a NativeWindow and registers event handlers to it. The event handlers do nothing more than queue the resulting events.
- Calls NativeWindow.ProcessEvents() in a loop. The event handlers queue the results.
- Does not interact with NativeWindow in any other way.
- Creates the OpenGL context and attaches it to the NativeWindow.
- Performs all program logic and rendering, including swapping framebuffers.
- Does not directly use NativeWindow's events. Instead, the GUI thread's queued events are used.
- Directly accesses NativeWindow's properties such as NativeWindow.Bounds and NativeWindow.WindowInfo.
The message queues get locked as needed, but the NativeWindow is never locked. Setting up locks on the NativeWindow only causes the GUI thread to freeze. I'm no expert on multithreading, so I've not found a solution to the latter.
This solution works now, but I worry that if the planets go out of alignment it could all come crashing down. Any ideas?