我找不到如何声明runtime.LockOSThread()和runtime.UnlockOSThread()。我将它定义为runtime.LockOSThread(),一些代码runtime.UnlockOSThread()。但是它给出了错误,未定义: runtime.LockOSThread和未定义: runtime.UnlockOSThread。有人能建议我如何定义它吗?更重要的是,我这样定义它,
Routine 1 {
runtime.LockOSThread()
do something
runtime.UnlockOSThread
}
main {
routine1
}发布于 2011-12-05 01:40:12
例如,
package main
import "runtime"
func routine() {
runtime.LockOSThread()
runtime.UnlockOSThread()
}
func main() {
go routine()
}发布于 2011-12-05 01:34:17
如有疑问,请参阅the documentation。
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.https://stackoverflow.com/questions/8376968
复制相似问题