Somewhat easier than using lock() all over your code, is to wrap print in your own sub that does that for you:
use threads; use threads::shared; my $sem :shared; sub tprint { my $tid = threads->tid; lock $sem; print "$tid: ",@_, "\n"; } sub twarn { my $tid = threads->tid; lock $sem; warn "$tid: ", @_; }
In reply to Re: multithread and STDOUT locking
by BrowserUk
in thread multithread and STDOUT locking
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |