in reply to Threads question

two points: first, perl threads cannot be started and forgot. you must explicitly call the join() method on each of your threads.
second, for the unpredictable output: set the $| variable to an nonzero value, by which you force perl to autoflush any output. this may be done globally, or within the printing sub:
local $| = 1
you will find further explanations in perldoc perlvar

--------------------------------
masses are the opiate for religion.

Replies are listed 'Best First'.
Re^2: Threads question
by xiaoyafeng (Deacon) on Jun 29, 2007 at 03:04 UTC
    Actually, I copy the code from perlthrtut.
    I don't see any comment or code at there that let me add $|++ or use join method on each thread. Anyway, if you are right, I doubt whether thread tutorial is clear enough.

    I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction
Re^2: Threads question
by ikegami (Patriarch) on Jun 29, 2007 at 15:18 UTC
    It's not a buffering issue. You have two threads trying to access the same resource (STDOUT). Whenever that happens, you have to use a locking mechanism to ensure a thread is done with the resource before another thread can use it.