Tcl Thread: Como acessar variáveis globais no thread
Eu tenho um proc chamado "startMyProc {num}". Quero que esse proc seja chamado por dois threads diferentes e aguarde a conclusão de ambos os threads. Eu tentei a solução dada que está funcionando. Eu quero acessar as variáveis globais em startMyProc e chamar outro proc "startMyAnotherProc {num}". Como isso pode ser feito?
package require Thread
global myVar
set myVar false
set id1 [thread::create -joinable {
source sample.tcl
thread::wait
}]
set id2 [thread::create -joinable {
source sample.tcl
thread::wait
}]
set num 1
thread::send -async $id1 [list startMyProc $num]
set num 2
thread::send -async $id2 [list startMyProc $num]
thread::join $id1
thread::join $id2
My sample.tcl looks like this,
proc startMyProc { num } {
global myVar
puts $myVar
puts "Opening $num"
after 2000
puts "Opening $num"
after 2000
puts "Opening $num"
after 2000
startMyAnotherProc $myVar
return
}
proc startMyAnotherProc { num } {
puts "Opening Another Proc: $num"
after 2000
puts "Opening Another Proc: $num"
after 2000
return
}