Improved run locking to avoid deadlock