Re: Reg - Multi thread execution
- From: Alexandre Ferrieux <alexandre.ferrieux@xxxxxxxxx>
- Date: Wed, 17 Sep 2008 23:26:05 -0700 (PDT)
On Sep 18, 7:50 am, 2boopa...@xxxxxxxxx wrote:
Hi ,
We are trying to use multiple thread to execute procedures in
parallel.
Thread_sample.tcl does the below.
proc Proc1, Proc2, Proc3 are defined.
Created 3 threads
sending the proc name to each thread for execution.
Content of Thread_sample.tcl
package require Thread
proc Proc1 {} {
puts "This is from proc1"
}
proc Proc2 {} {
puts "This is from proc2"
}
proc Proc3 {} {
puts "This is from proc3"
}
set Thread1 [thread::create]
set Thread2 [thread::create]
set Thread3 [thread::create]
thread::send $Thread1 "Proc1"
thread::send $Thread2 "Proc2"
thread::send $Thread3 "Proc3"
Getting below error while execution
D:\>tclsh Thread_sample.tcl
invalid command name "Proc1"
while executing
"Proc1"
invoked from within
"thread::send $Thread1 "Proc1""
(file "Thread_sample.tcl" line 20)
Kindly let us know what is the issue with the above code.
Thanks
P.Boopathi
In Tcl there's a separate interpreter per thread.
So when you say "proc ..." it only creates the proc for the current
interpreter+thread.
To instruct other threads to execute some code, you must send them all
the material before, just like building your villa on a desert island:
thread::send $thr {
proc foo
proc ...
set ::someglobal ...
...
}
then
thread::send $thr {foo ...}
-Alex
.
- References:
- Reg - Multi thread execution
- From: 2boopathi
- Reg - Multi thread execution
- Prev by Date: variable defination
- Next by Date: Re: variable defination
- Previous by thread: Reg - Multi thread execution
- Next by thread: variable defination
- Index(es):
Relevant Pages
|