Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion aten/src/ATen/MapAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <atomic>
#include <string>
#include <random>
#if ATOMIC_INT_LOCK_FREE == 2
#define AT_ATOMIC_IPC_REFCOUNT 1
#endif
Expand Down Expand Up @@ -34,13 +35,16 @@ static constexpr int64_t map_alloc_alignment = 64;

TORCH_API std::string NewProcessWideShmHandle()
{
static std::atomic<uint64_t> counter;
static std::atomic<uint64_t> counter{0};
static std::random_device rd;
std::string handle = "/torch_";
#ifdef _MSC_VER
handle += c10::guts::to_string(GetCurrentProcessId());
#else
handle += c10::guts::to_string(getpid());
#endif
handle += "_";
handle += c10::guts::to_string(rd());
handle += "_";
handle += c10::guts::to_string(counter.fetch_add(1, std::memory_order_relaxed));
return handle;
Expand Down