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

Mehdi Amini llvmlistbot at llvm.org
Sat Mar 16 16:24:19 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.
----------------
joker-eph wrote:

> So after this function static variable registry is destructed by some thread, the other threads could still be using it,

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

 > Are you having a case when the program exit, the global destructors are called, but you still then will see a call to this registerImplicitTypeID?


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.

(I'm not saying we shouldn't be resilient here on our side, but just clarifying that your backtrace looks to me like a problem with your setup somehow).

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


More information about the Mlir-commits mailing list