#!/usr/local/perl_ithreads/bin/perl use strict; use warnings; use threads; use threads::shared; our %h = ( a => 1, b => 2, c => 3 ); share( $h{ a } ); share( $h{ b } ); share( $h{ c } ); our @locking_keys = qw/ a b /; { # this loop introduces another block context lock( $h{ $_ } ) for @locking_keys; # here I wish to munge all of the lock # things at the same time, say copy data # from one to another. # this gives a warning, because the block # context of the above loop has already been # exited, causing the locks to be lost cond_signal( $h{ $_ } ) for @locking_keys; } { my @left_to_lock = @locking_keys; my $key; LOCK_LOOP: $key = pop @left_to_lock; lock( $h{ $key } ); goto LOCK_LOOP if @left_to_lock; # now the things are really locked, and so no warning is issued here cond_signal( $h{ $_ } ) for @locking_keys; }