make dispose thread-safe to avoid unexpected leaks during register/dispose interleavings