| Some libraries, especially graphical frameworks/libraries like Cocoa, OpenGL, libSDL all require it's |
| called from the main OS thread or called from the same OS thread due to its use of thread local |
| data structures. Go's runtime provides ` LockOSThread() ` function for this, but it's notoriously difficult |
| Russ Cox presented a good solution for this problem in this [thread](https://groups.google.com/d/msg/golang-nuts/IiWZ2hUuLDA/SNKYYZBelsYJ). |
| // Arrange that main.main runs on main thread. |
| // Main runs the main SDL service loop. |
| // The binary's main.main must call sdl.Main() to run this loop. |
| // Main does not return. If the binary needs to do other work, it |
| // must do it in separate goroutines. |
| for f := range mainfunc { |
| // queue of work to run in main thread. |
| var mainfunc = make(chan func()) |
| // do runs f on the main thread. |
| done := make(chan bool, 1) |
| And then other functions you write in package sdl can be like |
| // whatever must run in main thread |