#!/usr/bin/perl -w use strict; use threads; for (my $i = 0; $i < 5000; $i++){ my $thr = threads->create( \&_run_thread, $i ); sleep 1; } # make sure all threads complete while ( threads->list(threads::running) ){ sleep 1; }; print "ok.\n"; sub _run_thread { my ($id) = @_; print "starting thread $id ...\n"; sleep 4; print "exiting thread $id.\n"; return; }