マルチスレッドを使用して200ファイルを取得したいので、以下のようにTCLの例を変更します。 しかし、結果は奇妙です。出力ファイルの総数は約135です。スレッドの開始方法が変数$thread
の値を変更するのは混乱していました。TCLでループを使ってマルチ・シアドを始めるには?
package require Thread
puts "*** I'm thread [thread::id]"
for {set thread 1} {$thread <= 200} {incr thread} {
set thread_ida $thread
tsv::set app global_thread_num $thread_ida
set id [thread::create -joinable {
puts [ tsv::get app global_thread_num ]
set thread_id [ tsv::get app global_thread_num ]
puts "${thread_id}thread_id"
set outFile "./test/${thread_id}"
append outFile ".tmd"
puts $outFile
set FileOut [open $outFile w+]
puts $FileOut "${thread_id}thread_id"
}] ;# thread::create
puts "*** Started thread $id"
lappend threadIds $id
} ;# for
puts "*** Existing threads: [thread::names]"
# Wait until all other threads are finished
foreach id $threadIds {
thread::join $id
}
puts "*** That's all, folks!"
私が使用している作業負荷がより複雑であると仮定しています。単一のスレッドで200個のファイルのそれぞれに1行だけを書き込むほうが簡単です。 –
私のtclファイルをあなたのものとして修正しています。本当にありがとうございました〜そして、ついに間違いを見つけました〜私はスレッドを使用して、200本のファイルのそれぞれに1行だけ書くのではなく、 –