Proper threads_enter/threads_leave pairing