[Mlir-commits] [mlir] fix a concurrent destruction issue for FallbackTypeIDResolver::registerImplicitTypeID due to function static variable (PR #85471)

Li Deng llvmlistbot at llvm.org
Sat Mar 16 16:42:50 PDT 2024


================
@@ -81,8 +81,11 @@ struct ImplicitTypeIDRegistry {
 } // end namespace
 
 TypeID detail::FallbackTypeIDResolver::registerImplicitTypeID(StringRef name) {
-  static ImplicitTypeIDRegistry registry;
-  return registry.lookupOrInsert(name);
+    // To prevent race conditions when one thread is accessing this `static`
+    // variable while other threads are destructing it; construct the `registry`
+    // on the heap.
----------------
dengl11 wrote:

> This is exactly what I've been asking here isn't it?

Yep totally;

> In your case that means that the program is exiting but there is still a thread running a TensorFlow session: this seems like a problem in itself already.

Make sense;

Thanks for the suggested comments; now updated.

https://github.com/llvm/llvm-project/pull/85471


More information about the Mlir-commits mailing list