# Question regarding multithreading

**URL:** <https://discourse.glfw.org/t/question-regarding-multithreading/2827>\
**Category:** support\
**Created:** [January 30, 2025, 7:52pm UTC](https://discourse.glfw.org/t/question-regarding-multithreading/2827 "2025-01-30T19:52:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![constantitus](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/constantitus/32/994_2.png) [@constantitus](https://discourse.glfw.org/u/constantitus)\
**Post date:** [January 30, 2025, 7:52pm UTC](https://discourse.glfw.org/t/question-regarding-multithreading/2827/1 "2025-01-30T19:52:32Z")

</div>

The glfw documentation on Thread safety says the following:

> Most GLFW functions must only be called from the main thread (the thread that calls main), but some may be called from any thread once the library has been initialized. Before initialization the whole library is thread-unsafe.

Is there any specific reason that thread has to be the **main** thread and not a secondary one ? If so,what would that be ? As far as I know, windows lets you have the window on a non-main thread. I’m curious about X11 and wayland…  
The reason I’m asking is because I want to wrap glfw and some other platforms such as android into a higher level api and it’s easier to just fire off glfw on a secondary thread when creating the window, but if it has to be the main thread, that really adds a lot of constraints.

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [January 31, 2025, 2:57pm UTC](https://discourse.glfw.org/t/question-regarding-multithreading/2827/2 "2025-01-31T14:57:06Z")

</div>

Hi @constantitus,

This response [Multithreading GLFW? - #5 by elmindreda](https://discourse.glfw.org/t/multithreading-glfw/573/5) covers the reasons behind why some GLFW functions need to be called from the main thread.

---

<div class="post-metadata">

**Author:** ![constantitus](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/constantitus/32/994_2.png) [@constantitus](https://discourse.glfw.org/u/constantitus)\
**Post date:** [January 31, 2025, 4:31pm UTC](https://discourse.glfw.org/t/question-regarding-multithreading/2827/3 "2025-01-31T16:31:50Z")

</div>

I see, so the gist of it is that macos is the only platform that imposes this limitation and I’m fine with putting glfw on a non-main thread since I don’t care about macos. Am I right ?

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [January 31, 2025, 4:45pm UTC](https://discourse.glfw.org/t/question-regarding-multithreading/2827/4 "2025-01-31T16:45:55Z")

</div>

This would likely work well on other platforms than Mac OS X, but since it’s part of the GLFW spec there’s always a possibility something else gets introduced in future which might require the main thread, though I think that’s unlikely.

Working around this limitation usually isn’t too hard since you can still move rendering etc. to another thread.

---

<div class="post-metadata">

**Author:** ![constantitus](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/constantitus/32/994_2.png) [@constantitus](https://discourse.glfw.org/u/constantitus)\
**Post date:** [January 31, 2025, 4:57pm UTC](https://discourse.glfw.org/t/question-regarding-multithreading/2827/5 "2025-01-31T16:57:55Z")

</div>

Yes, I do rendering on the main thread and have glfw on a second thread. The main reason I wanted to isolate the window on another thread is because Windows blocks the window thread on resize. Otherwise I wouldn’t have bothered with polling events on another thread.

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [January 31, 2025, 5:51pm UTC](https://discourse.glfw.org/t/question-regarding-multithreading/2827/6 "2025-01-31T17:51:07Z")

</div>

The approach with GLFW is to do the reverse - put your rendering on a second thread and then GLFW functions which require the main thread can be used on the main thread.
