Static locking will be useful for controlling access to a static variable. Instance locking would be useful for controlling access to an instance variable.
It makes no sense to use a local lock object to protect a local variable (unless it is an anonymous function captured by an external variable or an iterator), since other threads will not have access to the lock, nor to the variable.
Jeffrey l whitledge
source share