Properly construct the scoped locks for thread synchronization