2016-04-05 14 views
1

私はTCLスレッドを使用しています。私は3つのスレッドを開き、各スレッドで単純なprintステートメントを開く簡単なプログラムを作成しようとしています。以下は TCLスレッドが出力を印刷しない理由

は出力

*** I'm thread tid00004028 
*** Started thread tid0000A5E8 
*** Started thread tid00009F28 
*** Started thread tid00009D54 
*** Existing threads: tid00009D54 tid00009F28 tid0000A5E8 tid00004028 
*** That's all, folks! 
+2

私はその正確なコードを試してくれます。 –

+0

印刷は何ですか?出力を表示できますか – Nitesh

+0

私はウィンドウでTcl 8.4を使用しています – Nitesh

答えて

2

あなたはTclの8.4を使用しているコメントから、あなたが得ようとしているアドバイスは簡単ですので、私のコードの下に

package require Thread 
puts "*** I'm thread [thread::id]" 
# Create 3 threads 
for {set thread 1} {$thread <= 3} {incr thread} { 
    set id [thread::create { 
    # Print a hello message 3 times, waiting 
    # a random amount of time between messages 
     for {set i 1} {$i <= 3} {incr i} { 
      after [expr { int(500*rand()) }] 
      puts "Thread [thread::id] says hello" 
     } 
    }] ;# thread::create 
    puts "*** Started thread $id" 
} ;# for 
puts "*** Existing threads: [thread::names]" 
# Wait until all other threads are finished 
while {[llength [thread::names]] > 1} { 
after 500 
} 
puts "*** That's all, folks!" 

されている。アップグレードをTclのサポートされているバージョンに置き換えます。私はあなたがOSX上でtclsh8.5とtclsh8.6の両方で投稿した正確なコードを試しました。ここでは8.5で実行します:

 
*** I'm thread tid0x7fff758f3180 
*** Started thread tid0x104326000 
*** Started thread tid0x1043ac000 
*** Started thread tid0x1044b2000 
*** Existing threads: tid0x1044b2000 tid0x1043ac000 tid0x104326000 tid0x7fff758f3180 
Thread tid0x1043ac000 says hello 
Thread tid0x104326000 says hello 
Thread tid0x104326000 says hello 
Thread tid0x1044b2000 says hello 
Thread tid0x1043ac000 says hello 
Thread tid0x1044b2000 says hello 
Thread tid0x104326000 says hello 
Thread tid0x1044b2000 says hello 
Thread tid0x1043ac000 says hello 
*** That's all, folks! 

スレッド-IDは、他のプラットフォーム上ではかなり異なる場合があります(そのフォーマットは仕様の一部ではない)が、それはあなたが得るものの一種である必要があります。もちろん、順序のモジュロバリエーション。

Tcl 8.4はセキュリティ修正プログラムでもサポートされなくなりました。それは8.4.20がリリースされた後に終わったのです。

+0

ちょうど情報の目的のために、私の質問は、スレッドパッケージtclsh8.6のinbuiltですか?ここで、スレッドパッケージは、tclsh8.4を使用してスレッドにアクセスしようとしているときにはそこにありません。私の理解は正しいのですか? –

+1

スレッドパッケージは8.4の外部にありました。寄付されたすべてのパッケージをスキップする、本当に素人のビルドをしない限り、それは8.6でなければなりません。 –

関連する問題