synchronizing a block of code with a lock