如何声明runtime.LockOSThread()和runtime.

我找不到如何声明runtime.LockOSThread()和runtime.UnlockOSThread()的方法。我像[runtime.LockOSThread()]那样定义一些代码[runtime.UnlockOSThread()]。但是它给出了错误,未定义:runtime.LockOSThread和未定义:runtime.UnlockOSThread。有人可以建议我如何定义它吗?对于更多,我将其定义为


Routine 1 {

runtime.LockOSThread()

do something

runtime.UnlockOSThread


}


main {

routine1

}


浮云间
浏览 249回答 2
2回答

慕工程0101907

例如,package mainimport "runtime"func routine() {    runtime.LockOSThread()    runtime.UnlockOSThread()}func main() {    go routine()}

繁花不似锦

如有疑问,请参阅文档。func LockOSThread()LockOSThread wires the calling goroutine to its current operating system thread.Until the calling goroutine exits or calls UnlockOSThread, it will always execute inthat thread, and no other goroutine can.func UnlockOSThread()UnlockOSThread unwires the calling goroutine from its fixed operating system thread.If the calling goroutine has not called LockOSThread, UnlockOSThread is a no-op.
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go