Tcl Thread: Cómo acceder a variables globales en thread
Tengo un proceso llamado "startMyProc {num}". Quiero que este proceso sea llamado por dos hilos diferentes y espero a que se completen ambos hilos. Probé la solución dada que está funcionando. Quiero acceder a las variables globales en startMyProc y llamar a otro proceso "startMyAnotherProc {num}". ¿Cómo se puede hacer esto?
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
}