I just realized that in some place in my code I have the return statement inside the lock and sometime outside. Which one is the best?
1)
void exampl
I would definitely put the return inside the lock. Otherwise you risk another thread entering the lock and modifying your variable before the return statement, therefore making the original caller receive a different value than expected.