#!/usr/bin/perl -w -l -- @ARGV = qw[ foo bar baz ]; use threads; $|=1; sub f :locked { my $tid = threads->self()->tid(); print "A}$tid}$_[0]"; select undef, undef, undef, rand(2); print "B}$tid}$_[0]"; } threads->create(\&f, $_) for @ARGV; $_->join() for threads->list() __END__ A}1}foo A}2}bar A}3}baz B}3}baz B}2}bar B}1}foo #!/usr/bin/perl -w -l -- @ARGV = qw[ foo bar baz ]; use threads; $|=1; sub f :locked { my $tid = threads->self()->tid(); print "A}$tid}$_[0]"; select undef, undef, undef, rand(2); print "B}$tid}$_[0]"; } threads->create(\&f, $_) for @ARGV; $_->join() for threads->list() __END__ A}1}foo A}2}bar A}3}baz B}1}foo B}2}bar B}3}baz