sub threadwork(){ lock(MUTEX); do{ the work; } } $t = new threadpool(42 threads); $t->do( &threadwork() ); lock(MUTEX); loop{ ct = timestamp(); sleep(0.9 seconds); # do a blocking select with timeout in perl for microsecond timings loop {nop;} while (ct==timestamp()); # the spinloop #or, for a interval of 5 seconds: while ( ct+5>timestamp() ); unlock(MUTEX); }