2011-12-04 8 views
0

runtime.LockOSThread()runtime.UnlockOSThread()を宣言する方法を見つけることができませんでした。私は[runtime.LockOSThread()]のようないくつかのコード[runtime.UnlockOSThread()]のように定義します。しかし、それはundefined:runtime.LockOSThreadとundefined:runtime.UnlockOSThreadというエラーを与えています。誰も私にそれを定義する方法を提案することができますか?詳細については、runtime.LockOSThread()とruntime.UnlockOSThread()を宣言する方法

Routine 1 { 
runtime.LockOSThread() 
do something 
runtime.UnlockOSThread 

} 

main { 
routine1 
} 

答えて

2

、 `runtime.LockOSThread()`と `runtime.UnlockOSThread()`のドキュメントへ

package main 

import "runtime" 

func routine() { 
    runtime.LockOSThread() 
    runtime.UnlockOSThread() 
} 

func main() { 
    go routine() 
} 
+0

ありがとうございました。私はこのコードをhttp://play.golang.org/で実行しようとしているため、申し訳ありません。それがエラーを出す理由です。私のデスクトップでは、このコード(と私のサンプルコードも)が正しく動作しています。 – Arpssss

1

のように定義します。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. 
+0

質問リンク。 – peterSO

関連する問題