I am confused how the $foo variable is locked in the functions.
Through the magic of perl threads?
I'm sorry, I don't understand your question, but I don't think I could explain lock better than perlthrtut.
Maybe it would be easier for you to understand if you told us where you got that code, what its supposed to do, etc?
Comment on Re^3: Help on Understanding Locks in Multithreading