Here is my code:
package require Thread
proc Serve {Channel args} {
set Thread [thread::create]
thread::transfer $Thread $Channel
thread::send $Thread {
proc SayYes {Channel} {
while {true} {
puts $Channel yes
}
}
}
thread::send -async $Thread SayYes\ $Channel
}
socket -server Serve 8080
vwait Forever
When I do `nc localhost 8080` while this is running, it ends up showing
this error message;
channel is shared
while executing
"thread::transfer $Thread $Channel"
(procedure "Serve" line 3)
invoked from within
"Serve sockb865ea58 127.0.0.1 55037"
and closing the connection. When I omit transferring `Channel`, I get this;
or from thread tid0xb6b08930
can not find channel named "sockb8aaea58"
while executing
"puts $Channel yes"
(procedure "SayYes" line 3)
invoked from within
"SayYes sockb8aaea58"
What should I do ? Please help.
|