Issue #7264: Fix a possible deadlock when deallocating thread-local objects