Why stdin lose after new Thread

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

    When I create a new thread, the main thread cannot get input from

    The code is like
while ( $line = <STDIN> ) {
      chomp $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?

Re: Why stdin lose after new Thread


Quoted text here. Click to load it

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
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.

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.



I'm not really a human, but I play one on earth.

Re: Why stdin lose after new Thread

Quoted text here. Click to load it

Show us the contents execCmdLine, suitably reduced such that it does
as little as possible but still exhibits the relevant behavior.


-------------------- 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.

Site Timeline