|
Prev: newbie
Next: chinese words in tcl/expect
From: yahalom on 6 Jul 2008 07:55 I try to use ttrace to change global variable in all threads but it does not work. my code: package require Thread package require Ttrace set t1 [thread::create] set t2 [thread::create] foreach t {t1 t2} { thread::send [set $t] {proc a {} { puts $::glb } set glb 1 } } thread::send $t1 a thread::send $t2 a ttrace::eval set ::glb 2 ttrace::eval proc c {} {puts hello} thread::send $t1 a thread::send $t2 a thread::send $t2 c result: 1 1 1 1 hello what am I doing wrong? ttrace seems to work fine with methods but not with variables.
From: Alexandre Ferrieux on 6 Jul 2008 08:16 On Jul 6, 1:55 pm, yahalom <yahal...(a)gmail.com> wrote: > I try to use ttrace to change global variable in all threads but it > does not work. my code: > package require Thread > package require Ttrace > > set t1 [thread::create] > set t2 [thread::create] > foreach t {t1 t2} { > thread::send [set $t] {proc a {} { > puts $::glb > > } > set glb 1 > } > } > > thread::send $t1 a > thread::send $t2 a > ttrace::eval set ::glb 2 > ttrace::eval proc c {} {puts hello} > thread::send $t1 a > thread::send $t2 a > thread::send $t2 c > > result: > 1 > 1 > 1 > 1 > hello > > what am I doing wrong? ttrace seems to work fine with methods but not > with variables. Well, it was my understanding that ttrace worked only in a lazy fashion, by pulling only the necessary procs as discovered by [unknown] in the target thread/interp. No such thing exists for variables AFAIK. (of course a variable trace could be added, but the performance hit would be huge since it would affect all variables, not only those to be transmitted). If you want to propagate a {set variable value}, why not just ::thread::send it to all threads ? -Alex
From: yahalom on 6 Jul 2008 08:58 On Jul 6, 9:16 pm, Alexandre Ferrieux <alexandre.ferri...(a)gmail.com> wrote: > On Jul 6, 1:55 pm, yahalom <yahal...(a)gmail.com> wrote: > > > > > > > I try to use ttrace to change global variable in all threads but it > > does not work. my code: > > package require Thread > > package require Ttrace > > > set t1 [thread::create] > > set t2 [thread::create] > > foreach t {t1 t2} { > > thread::send [set $t] {proc a {} { > > puts $::glb > > > } > > set glb 1 > > } > > } > > > thread::send $t1 a > > thread::send $t2 a > > ttrace::eval set ::glb 2 > > ttrace::eval proc c {} {puts hello} > > thread::send $t1 a > > thread::send $t2 a > > thread::send $t2 c > > > result: > > 1 > > 1 > > 1 > > 1 > > hello > > > what am I doing wrong? ttrace seems to work fine with methods but not > > with variables. > > Well, it was my understanding that ttrace worked only in a lazy > fashion, by pulling only the necessary procs as discovered by > [unknown] in the target thread/interp. No such thing exists for > variables AFAIK. (of course a variable trace could be added, but the > performance hit would be huge since it would affect all variables, not > only those to be transmitted). > > If you want to propagate a {set variable value}, why not > just ::thread::send it to all threads ? > > -Alex- Hide quoted text - > > - Show quoted text - well, I though ttrace will do it so I experimented with it. I need to spread it to tclhttpd threads so I did not want to dig in tclhttpd code if ttrace work. now I digged and found the global Thread(threadlist) so I will try the thread::send.
From: Alexandre Ferrieux on 6 Jul 2008 12:03 On Jul 6, 2:58 pm, yahalom <yahal...(a)gmail.com> wrote: > On Jul 6, 9:16 pm, Alexandre Ferrieux <alexandre.ferri...(a)gmail.com> > wrote: > > > > > > > On Jul 6, 1:55 pm, yahalom <yahal...(a)gmail.com> wrote: > > > > I try to use ttrace to change global variable in all threads but it > > > does not work. my code: > > > package require Thread > > > package require Ttrace > > > > set t1 [thread::create] > > > set t2 [thread::create] > > > foreach t {t1 t2} { > > > thread::send [set $t] {proc a {} { > > > puts $::glb > > > > } > > > set glb 1 > > > } > > > } > > > > thread::send $t1 a > > > thread::send $t2 a > > > ttrace::eval set ::glb 2 > > > ttrace::eval proc c {} {puts hello} > > > thread::send $t1 a > > > thread::send $t2 a > > > thread::send $t2 c > > > > result: > > > 1 > > > 1 > > > 1 > > > 1 > > > hello > > > > what am I doing wrong? ttrace seems to work fine with methods but not > > > with variables. > > > Well, it was my understanding that ttrace worked only in a lazy > > fashion, by pulling only the necessary procs as discovered by > > [unknown] in the target thread/interp. No such thing exists for > > variables AFAIK. (of course a variable trace could be added, but the > > performance hit would be huge since it would affect all variables, not > > only those to be transmitted). > > > If you want to propagate a {set variable value}, why not > > just ::thread::send it to all threads ? > > > -Alex- Hide quoted text - > > > - Show quoted text - > > well, I though ttrace will do it so I experimented with it. I need to > spread it to tclhttpd threads so I did not want to dig in tclhttpd > code if ttrace work. now I digged and found the global > Thread(threadlist) so I will try the thread::send.- Hide quoted text - No need to dig. See [thread::names]. -Alex
|
Pages: 1 Prev: newbie Next: chinese words in tcl/expect |