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

Clement Courbet via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 12 00:05:24 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);
----------------
legrosbuffle wrote:

You can use `llvm::formatv`: https://godbolt.org/z/ox3hPc4fr

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


More information about the llvm-commits mailing list