multithreading - Why doesn't Go's LockOSThread lock this OS thread? -


the documentation runtime.lockosthread states:

lockosthread wires calling goroutine current operating system thread. until calling goroutine exits or calls unlockosthread, execute in thread, , no other goroutine can.

but consider program:

package main  import (     "fmt"     "runtime"     "time" )  func main() {     runtime.gomaxprocs(1)     runtime.lockosthread()     go fmt.println("this shouldn't run")     time.sleep(1 * time.second) } 

the main goroutine wired 1 available os thread set gomaxprocs, expect goroutine created on line 3 of main not run. instead program prints this shouldn't run, pauses 1 second, , quits. why happen?

from runtime package documentation:

the gomaxprocs variable limits number of operating system threads can execute user-level go code simultaneously. there no limit number of threads can blocked in system calls on behalf of go code; not count against gomaxprocs limit.

the sleeping thread doesn't count towards gomaxprocs value of 1, go free have thread run fmt.println goroutine.


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -