You're redirecting STDERR and STDOUT in a multi-threaded environment for logging? That's brave :)
You could try localising STDOUT and STDERR in the thread before calling inner_worker:
local *STDOUT; local *STDERR;
EDIT: Also:
can be re-written thusly:my $thread1 = threads->create ( \&worker, 1, 'sub1.log' ); my $thread2 = threads->create ( \&worker, 2, 'sub2.log' ); my $need_to_continue = 1; while ($need_to_continue) { print "MAIN THREAD IS PRINTING\n"; if ( $thread1->is_running() || $thread2->is_running() ) { sleep 3; } else { $need_to_continue = 0; } } $thread1->join(); $thread2->join(); exit 0;
join is a blocking process that waits for the thread to complete.my @threads = map {threads->new(\&worker, $_, "sub$_.log")} 1..2; $_->join for @threads; exit 0;
In reply to Re: capturing output of system call inside a thread
by SimonPratt
in thread capturing output of system call inside a thread
by that_guy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |