You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I plan to bind a functionality in my app to not run in parallel but without losing the concurrency solutions, much like a GIL but for a specific thread. I planned to use runtime.LockOSThread() but the documentation is unclear.
First of all is the current goroutine that will bind to a OS thread or is the next being created?
And second any goroutine created by the one locked to the OS thread will also execute exclusively to that OS thread or any other?
LockOSThread wires the calling goroutine to its current operating system thread.
(emphasis mine)
So in your program it is the main goroutine (the one executing the main function) that is locked to a specific OS thread (and no other goroutine may execute in that thread).
It is just a coincidence that the other two goroutines execute in the same thread. There is no facility to ensure that a group of goroutines all execute in the same thread (although the scheduler is likely smart enough to run related goroutines in the same thread).
Closing this issue because the docs are explicit about which goroutine is locked to the thread.
I plan to bind a functionality in my app to not run in parallel but without losing the concurrency solutions, much like a GIL but for a specific thread. I planned to use runtime.LockOSThread() but the documentation is unclear.
First of all is the current goroutine that will bind to a OS thread or is the next being created?
And second any goroutine created by the one locked to the OS thread will also execute exclusively to that OS thread or any other?
I used an example suggested here:
And I come up with the result:
It looks that the second goroutine executes in the same OS thread as the first one (witch fits my needs but I don't know if is a reliable way).
The text was updated successfully, but these errors were encountered: