From: Vincent Pit Date: Tue, 31 Mar 2015 20:06:12 +0000 (-0300) Subject: Improve scheduling for the parallel loading test X-Git-Tag: rt100068~1 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=79558d914ebc87d07b7eaca9d43293798418c93d;p=perl%2Fmodules%2Findirect.git Improve scheduling for the parallel loading test --- diff --git a/t/09-load-threads.t b/t/09-load-threads.t index d0e4322..1f000c1 100644 --- a/t/09-load-threads.t +++ b/t/09-load-threads.t @@ -174,16 +174,24 @@ is_loaded 0, 'main body, after nested loadings'; use threads; use threads::shared; -my @locks = (1) x 5; -share($_) for @locks; +my @locks_down = (1) x 5; +my @locks_up = (0) x scalar @locks_down; +share($_) for @locks_down, @locks_up; + +my $peers = 2; sub sync_master { my ($id) = @_; { - lock $locks[$id]; - $locks[$id] = 0; - cond_broadcast $locks[$id]; + lock $locks_down[$id]; + $locks_down[$id] = 0; + cond_broadcast $locks_down[$id]; + } + + { + lock $locks_up[$id]; + cond_wait $locks_up[$id] until $locks_up[$id] == $peers; } } @@ -191,8 +199,14 @@ sub sync_slave { my ($id) = @_; { - lock $locks[$id]; - cond_wait $locks[$id] until $locks[$id] == 0; + lock $locks_down[$id]; + cond_wait $locks_down[$id] until $locks_down[$id] == 0; + } + + { + lock $locks_up[$id]; + $locks_up[$id]++; + cond_signal $locks_up[$id]; } } @@ -237,7 +251,7 @@ SKIP: { return; }); - sync_master($_) for 0 .. $#locks; + sync_master($_) for 0 .. $#locks_down; $thr1->join; if (my $err = $thr1->error) {