my $stdout_mutex :shared; { lock($stdout_mutex); print ...; }