OSDN Git Service

[ORC] Lock ThreadSafeContext during module destruction in ThreadSafeModule's
authorLang Hames <lhames@gmail.com>
Fri, 28 Sep 2018 01:41:29 +0000 (01:41 +0000)
committerLang Hames <lhames@gmail.com>
Fri, 28 Sep 2018 01:41:29 +0000 (01:41 +0000)
move constructor.

This is basically the same fix as r343261, but applied to the move constructor:
Failure to lock the context during module destruction can lead to data races if
other threads are operating on the context.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343286 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ExecutionEngine/Orc/ThreadSafeModule.h

index f763b9b..d1a786c 100644 (file)
@@ -93,6 +93,12 @@ public:
     // reverse order (i.e. module first) to ensure the dependencies are
     // protected: The old module that is being overwritten must be destroyed
     // *before* the context that it depends on.
+    // We also need to lock the context to make sure the module tear-down
+    // does not overlap any other work on the context.
+    if (M) {
+      auto L = getContextLock();
+      M = nullptr;
+    }
     M = std::move(Other.M);
     TSCtx = std::move(Other.TSCtx);
     return *this;