diff --git a/be/src/util/core_local.cpp b/be/src/util/core_local.cpp index 9c9a8a4cd384e9..30cda25f078852 100644 --- a/be/src/util/core_local.cpp +++ b/be/src/util/core_local.cpp @@ -21,6 +21,7 @@ #include #include "common/logging.h" +#include "util/spinlock.h" namespace doris { @@ -48,8 +49,11 @@ class CoreDataAllocatorImpl : public CoreDataAllocator { virtual ~CoreDataAllocatorImpl(); void* get_or_create(size_t id) override { size_t block_id = id / ELEMENTS_PER_BLOCK; - if (block_id >= _blocks.size()) { - _blocks.resize(block_id + 1); + { + std::lock_guard l(_lock); + if (block_id >= _blocks.size()) { + _blocks.resize(block_id + 1); + } } CoreDataBlock* block = _blocks[block_id]; if (block == nullptr) { @@ -61,6 +65,7 @@ class CoreDataAllocatorImpl : public CoreDataAllocator { } private: static constexpr int ELEMENTS_PER_BLOCK = BLOCK_SIZE / ELEMENT_BYTES; + SpinLock _lock; // lock to protect the modification of _blocks std::vector _blocks; };