为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

Go
浮云间 2021-04-27 13:45:58
我找不到如何声明runtime.LockOSThread()和runtime.UnlockOSThread()的方法。我像[runtime.LockOSThread()]那样定义一些代码[runtime.UnlockOSThread()]。但是它给出了错误,未定义:runtime.LockOSThread和未定义:runtime.UnlockOSThread。有人可以建议我如何定义它吗?对于更多,我将其定义为Routine 1 {runtime.LockOSThread()do somethingruntime.UnlockOSThread}main {routine1}
查看完整描述

2 回答

?
慕工程0101907

TA贡献1887条经验 获得超5个赞

例如,


package main


import "runtime"


func routine() {

    runtime.LockOSThread()

    runtime.UnlockOSThread()

}


func main() {

    go routine()

}


查看完整回答
反对 回复 2021-05-10
?
繁花不似锦

TA贡献1851条经验 获得超4个赞

如有疑问,请参阅文档。


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 in

that 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.


查看完整回答
反对 回复 2021-05-10
  • 2 回答
  • 0 关注
  • 217 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信