Forcing goroutines into the same thread

你。 提交于 2019-12-04 03:10:46

To the best of my knowledge, not currently. I think the 'go-like' way to do this would be to write a Goroutine that runs in the GUI thread and services requests from other goroutines sent in over a channel. For example, you could have it read from a channel that accepts function pointers, and execute those functions.

Why do you want to do this? I believe runtime.LockOSThread() is necessary if you are creating a library binding from C code which uses thread-local storage. Otherwise, just let the scheduler multiplex the goroutines for you.

And note that runtime.LockOSThread() only prevents other goroutines from running in that thread until you call runtime.UnlockOSThread().

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!