[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:25:49 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 thread destructing it; construct the `registry`
+  // on the heap.
----------------
joker-eph wrote:

```suggestion
  // To prevent race conditions when one thread is accessing this `static`
  // variable while the program is exiting and another thread already destroyed
  // it; intentionally construct the `registry` on the heap and never delete it.
```

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


More information about the Mlir-commits mailing list