sub player { # ... Initialisation code ... { lock $counter; ++$sig_counter; cond_wait( $sig_counter ) until $sig_counter == 3; } # ... Playing code ... } sub recorder { # ... Initialisation code ... { lock $counter; ++$sig_counter; cond_wait( $sig_counter ) until $sig_counter == 3; } # ... Recording code ... } $sig_counter = 0; $player_thread = threads->create( \&player ); $recorder_thread = threads->create( \&recorder ); { # This block should wait for threads to init lock $sig_counter; cond_wait( $sig_counter ) until $sig_counter == 2; } { # This block should signal subs to start main code lock $sig_counter; ++$sig_counter; }