[PATCH] D104016: [Orc][examples] Join ListenerThread on early exit in LLJITWithRemoteDebugging

Stefan Gränitz via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 10 02:42:31 PDT 2021


sgraenitz created this revision.
sgraenitz added a reviewer: lhames.
Herald added a subscriber: jfb.
sgraenitz requested review of this revision.
Herald added a project: LLVM.

In case of an error and early exit we don't reach the end of the main() function, where we used to disconnect the remote executor explicitly. During disconnect we join the ListenerThread in RemoteTargetProcessControl. This won't happen in case of an error right now.

With this patch the destructor of RemoteTargetProcessControl attempts to disconnect as well. The new atomic flag `AttemptDisconnect` makes sure we only do this once.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104016

Files:
  llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/RemoteJITUtils.cpp


Index: llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/RemoteJITUtils.cpp
===================================================================
--- llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/RemoteJITUtils.cpp
+++ llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/RemoteJITUtils.cpp
@@ -50,6 +50,7 @@
   RemoteTargetProcessControl(ExecutionSession &ES,
                              std::unique_ptr<RPCChannel> Channel,
                              std::unique_ptr<RPCEndpoint> Endpoint);
+  ~RemoteTargetProcessControl();
 
   void initializeMemoryManagement();
   Error disconnect() override;
@@ -60,6 +61,7 @@
   std::unique_ptr<MemoryAccess> OwnedMemAccess;
   std::unique_ptr<MemoryManager> OwnedMemMgr;
   std::atomic<bool> Finished{false};
+  std::atomic<uint8_t> AttemptDisconnect{0};
   std::thread ListenerThread;
 };
 
@@ -80,6 +82,12 @@
   });
 }
 
+RemoteTargetProcessControl::~RemoteTargetProcessControl() {
+  // Avoid reportError() from the base class, because the ExecutionSession
+  // might have been deleted already.
+  consumeError(disconnect());
+}
+
 void RemoteTargetProcessControl::initializeMemoryManagement() {
   OwnedMemAccess = std::make_unique<MemoryAccess>(*this);
   OwnedMemMgr = std::make_unique<MemoryManager>(*this);
@@ -90,6 +98,10 @@
 }
 
 Error RemoteTargetProcessControl::disconnect() {
+  // Make sure we don't disconnect more than once.
+  if (AttemptDisconnect.fetch_or(1))
+    return Error::success();
+
   std::promise<MSVCPError> P;
   auto F = P.get_future();
   auto Err = closeConnection([&](Error Err) -> Error {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104016.351096.patch
Type: text/x-patch
Size: 1582 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210610/f6ef1086/attachment.bin>


More information about the llvm-commits mailing list