diff --git a/tt_metal/impl/buffers/buffer.cpp b/tt_metal/impl/buffers/buffer.cpp index 81031f72a392..9fc17224ac56 100644 --- a/tt_metal/impl/buffers/buffer.cpp +++ b/tt_metal/impl/buffers/buffer.cpp @@ -13,6 +13,7 @@ #include "tt_metal/types.hpp" #include +#include #include #include #include "tt_metal/common/base.hpp" @@ -25,7 +26,7 @@ namespace tt { namespace tt_metal { -size_t Buffer::next_unique_id = 0; +std::atomic Buffer::next_unique_id = 0; std::ostream& operator<<(std::ostream& os, const ShardSpec& spec) { tt::stl::reflection::operator<<(os, spec); @@ -249,7 +250,7 @@ Buffer::Buffer( if (size != 0) { validate_buffer_size_and_page_size(size, page_size, buffer_type, buffer_layout, shard_parameters); } - unique_id_ = next_unique_id++; + unique_id_ = next_unique_id.fetch_add(1); } std::shared_ptr Buffer::create( diff --git a/tt_metal/impl/buffers/buffer.hpp b/tt_metal/impl/buffers/buffer.hpp index e5eded3f655b..6f1259ea0fe2 100644 --- a/tt_metal/impl/buffers/buffer.hpp +++ b/tt_metal/impl/buffers/buffer.hpp @@ -303,7 +303,7 @@ class Buffer final { std::weak_ptr weak_self; size_t unique_id_; - static size_t next_unique_id; + static std::atomic next_unique_id; }; } // namespace v0