[llvm] [llvm-exegesis] Add thread IDs to subprocess memory names (PR #84451)

Aiden Grossman via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 11 19:38:54 PDT 2024


================
@@ -22,12 +23,21 @@ namespace exegesis {
 
 #if defined(__linux__) && !defined(__ANDROID__)
 
+long getCurrentTID() {
+  // We're using the raw syscall here rather than the gettid() function provided
+  // by most libcs for compatibility as gettid() was only added to glibc in
+  // version 2.30.
+  return syscall(SYS_gettid);
+}
+
 Error SubprocessMemory::initializeSubprocessMemory(pid_t ProcessID) {
   // Add the PID to the shared memory name so that if we're running multiple
   // processes at the same time, they won't interfere with each other.
   // This comes up particularly often when running the exegesis tests with
-  // llvm-lit
-  std::string AuxiliaryMemoryName = "/auxmem" + std::to_string(ProcessID);
+  // llvm-lit. Additionally add the TID so that downstream consumers
+  // using multiple threads don't run into conflicts.
+  std::string AuxiliaryMemoryName = "/" + std::to_string(getCurrentTID()) +
+                                    "auxmem" + std::to_string(ProcessID);
----------------
boomanaiden154 wrote:

`std::format` isn't available because LLVM's current C++ version is C++17, and `llvm::format` doesn't have any string conversions, being solely intended for output streams (from what I can tell).

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


More information about the llvm-commits mailing list