[llvm] [Offload] Implement `olShutDown` (PR #144055)
Joseph Huber via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 16 06:15:40 PDT 2025
================
@@ -168,15 +172,41 @@ void initPlugins() {
!std::getenv("OFFLOAD_DISABLE_VALIDATION");
}
-// TODO: We can properly reference count here and manage the resources in a more
-// clever way
Error olInit_impl() {
- static std::once_flag InitFlag;
- std::call_once(InitFlag, initPlugins);
+ // While the refcount increment ensures that only thread performs
+ // initialization, we need to ensure that other threads are blocked until it
+ // is completed - hence this mutex.
+ static std::mutex Init{};
+ std::lock_guard<std::mutex> Guard{Init};
----------------
jhuber6 wrote:
Forgot to submit the comment, you need to use the same mutex when you uninitialize. The global ref count doesn't even need to be atomic since it's mutex guarded. Refer to what I linked earlier.
https://github.com/llvm/llvm-project/pull/144055
More information about the llvm-commits
mailing list