Multithreading with GLFW

Hello everyone!

I was reading the GLFW docs and I noticed that number of functions are described as “only call from the main thread”. I’d like to know what that exactly means.

I’m on Linux and I’ve creating a program that:

  1. Starts with a main thread, let’s call it A.
  2. Spins a second thread, let’s call it B.
  3. In B, it initialized GLFW and opens a window and does some OpengGL.
  4. No GLFW or OpenGL calls are done from any other thread, but B.

Everything works! I’m definitely not running GLFW in the main thread, however, I’m running it in a single thread.

Now I’d like to know, which of these statements is true:

  1. I’m just lucky on Linux, this won’t work on Mac OS X.
  2. As long as you call GLFW and OpenGL from a single thread it’s fine.
  3. You can have a thread-per-contex/window, once you create a window in a thread X, all calls related to that window must be done in thread X.

Thank you very much,
Michal Štrba

See this thread: Multithreading GLFW? in particular the answer by @elmindreda which should answer your question. Let me know if you need further clarification.

1 Like

Thanks alot! That answer clarifies it very well.