When I create a new thread, the main thread cannot get input from
<>.
The code is like
-----------------------------------------------
while ( $line = <STDIN> ) {
chomp $line;
execCmdLine($line);
print "pp> ";
}
------------------------------------------------
In the execCmdLine function, if $line eq 'conn', a new thread is
created. Then
the main thread can not get any line at all.
How can I let the main thread continue?
You don't understand how threads in Perl work very well.
When a thread gets spawned, it gets a copy of it's parent at the time.
This means when you try to dynamically spawn threads, each previous
thread gets a copy of previous ones, and memory usage of the app tends
to increase, as the memory dosn't get cleaned up completely.
It is all very complex, and you can search groups.google.com for
"perl threads", I'm not going to try an explain all the complexities
here.
Unless you really need threads for some reason, like sharing variables,
you will be better off fork-and-exec'ing stuff, as the memory cleanup
will be better.
But....
I found that if you put the readkey in a thread, you can keep
the mainloop going while receiving input. I use the Glib event
loop system here, to make things easier.
See:
http://perlmonks.org?node_id=664462
zentara
--
I'm not really a human, but I play one on earth.
http://zentara.net/Remember_How_Lucky_You_Are.html
Show us the contents execCmdLine, suitably reduced such that it does
as little as possible but still exhibits the relevant behavior.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.