Proper fix for deadlock