my $stdOutSem :shared; sub tprint { lock $stdoutSem; print ref( $_[0] ) eq 'GLOB' ? shift() : () "[@{[ threads->tid ]}]:", @_; } sub tprintf { lock $stdoutSem; printf ref( $_[0] ) eq 'GLOB' ? shift() : () "[%s]" . $_[0], $_[ 1 .. $#_ ]; }