this question really comes from using threads. We know that in perl threads we have a function called blocking, and according to cpan http://perldoc.perl.org/threads/shared.html : blocking blocks the control blocking of the variable until the blocking is out of scope. Itβs good that if we write something like this:
1 sub foo{ 2 lock($obj) if threads::shared::is_shared($obj);
so that the lock area is from line 2 to line 4 or only line 2? if the expression "if" adds a block to it, then the lock ($ obj) can only be line 2, see my #comments
the answer is actually the question, but I want to add some conclusions:
I found that no matter how you write:
lock($ojb) if threads::shared::is_shared($obj);
or
if (threads::shared::is_shared($obj)) { lock($ojb); }
the blocking area is the same - the whole function foo ().
source share