You have two issues. First, by $flag::shared;, I think you actually meant my $flag : shared;;
i.e. you weren't actually creating a shared variable.
Second, if the signal gets delivered to the parent thread, then that will wake it up from its sleep, so you'll want something like sleep 10000 while 1 to keep it alive.