Tcl Thread: Zugriff auf globale Variablen im Thread
Ich habe einen Proc mit dem Namen "startMyProc {num}". Ich möchte, dass dieser Proc von zwei verschiedenen Threads aufgerufen wird und auf den Abschluss beider Threads wartet. Ich habe die angegebene Lösung ausprobiert, die funktioniert. Ich möchte auf die globalen Variablen in startMyProc zugreifen und einen anderen Proc "startMyAnotherProc {num}" aufrufen. Wie geht das?
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
}