我找不到如何声明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()
}
繁花不似锦
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.
- 2 回答
- 0 关注
- 248 浏览
添加回答
举报
0/150
提交
取消