forestcreature has asked for the wisdom of the Perl Monks concerning the following question:
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Synchronising threads with signals (or not)
by BrowserUk (Patriarch) on Feb 22, 2013 at 17:11 UTC | |
Re: Synchronising threads with signals (or not)
by Anonymous Monk on Feb 22, 2013 at 16:54 UTC | |
Re: Synchronising threads with signals (or not)
by forestcreature (Novice) on Feb 22, 2013 at 23:28 UTC | |
by BrowserUk (Patriarch) on Feb 23, 2013 at 07:28 UTC | |
Re: Synchronising threads with signals (or not)
by locked_user sundialsvc4 (Abbot) on Feb 22, 2013 at 20:56 UTC | |
by BrowserUk (Patriarch) on Feb 22, 2013 at 21:03 UTC | |
|