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
When I create more than one go routine and use the calling of windows.GetCurrentThreadId function in their function body, it returns same thread id. Note: go routine body contains time.Sleep() not to be stop its execution immeditately. I mean all go routines are still executed.
Go uses a user space scheduling model whereby a large number of goroutines are mapped onto a small (usually on the order of the number of cores your operating system exposes) number of operating system threads. When a goroutine executes time.Sleep, it is no longer runnable (obviously) and as part of going to sleep to yields back to the scheduler so that the thread can service other runnable goroutines.
It is possible (although I can't test it as I don't have access to a windows system) that over time calling windows.GetCurrentThreadId() will return essentially random values. To avoid this some users call runtime.LockOSThread to reserve the current thread for only the runnable goroutine.
Thank you for raising this issue. Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.
Thanks for your answer, It is totally obvious for me. But I would like to ask a question another. I know here is not place for discussion. Let's say we have a running go routine in a thread. Does Go allow to be executed another go routine in the same thread before running thread does not end? Do I have to use runtime.LockOSThread function to reserve the thread?
go 1.13
When I create more than one go routine and use the calling of windows.GetCurrentThreadId function in their function body, it returns same thread id. Note: go routine body contains time.Sleep() not to be stop its execution immeditately. I mean all go routines are still executed.
The text was updated successfully, but these errors were encountered: