sub proc1 { $q = Thread::Queue->new(); while($p = $q->dequeue()){ if($p eq 'exit'){ last; } ..... } $q->end(); threads->exit(); }