Dear monks,
I am trying to synchronise two processes (recording and playback) so that I can be reasonably certain that each begins at a similar time to the other---after any necessary initialisation required for each. I have tried to do this with threads, using a number of signalling schemes, however something is going wrong and I was wondering if anybody had a quick solution. Alternatively, perhaps there is a better way to achieve the same goal.
Here is a mockup:
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; }
I've also tried similar things with explicit cond_signal for each state instead of the counter (i.e. player_ready, recorder_ready, all_go, etc.), but everything stops once the threads are done initialising and signalling to the 'parent'.
Best regards, Jason
In reply to Synchronising threads with signals (or not) by forestcreature
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |