hello ive written the following code and am testing
it on windows.
im having problems making it run like it should.
its basically having problems with the read from
keyboard.
im not in particular sure how i should do it so that it
has no problems using that.
it kind of mangles up input,with the output its okay
every second it prints out something
but with the input i press some stuff
i hit enter and it doesnt print them afterwards
like the code was written
is it possible that the thread and the "main" are trying to write to the STDOUT handle at the same time?
how can i fix this ?



use threads; $thr = threads->new(\&sub1); sub sub1 { while(1){ print "THREAD: in da zone !! :) \n\n"; sleep 1; }; } while(1){ my $stuff=''; read STDIN , $stuff,10; print "MAIN:", $stuff , "\n" ; }

maybe i should try to see if STDOUT can be written to
and have a loop until it can be written instead
of print "MAIN:", $stuff , "\n" ;
i ask for your oppinions kind monks :)

Edit: g0n - code tags


In reply to perl threads wait application? by spx2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.