Polling events in one thread, rendering in another

Here’s my current project setup, which is targeting both Windows and Linux.

I create the window and setup the context in the main thread. I then reset the context for that thread (glfwMakeContextCurrent(NULL) and then allow the second thread to set the context and start rendering.

Back on the main thread, I have a loop that just calls the event poll, while the other thread is handling rendering/swapping buffers.

This appears to work without issue on both Linux and Windows, so I’ve been leaving it alone… but I am wondering what potential issues may crop up since I’m rendering in one thread and polling in another? I’m not using a mutex to synchronize them, although the main thread at this point is just sitting in a loop calling glfwPoll once every 50ms.

I know using a separate thread like this may seem unnecessary, but there is a reason for it.

But anyway, given all that, are there any potential issues that could crop up or, given that it is working in its current state, just leave well enough alone?

Hi @robertjdac,

So long as you keep the event polling on the main thread this is fine, and indeed is the same approach used by quite a few projects. You do have to be careful about synchronizing data between the two threads.

Perfect, understood - thank you very much!