diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBSCachingAllocator.cpp b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBSCachingAllocator.cpp index bb923a7d8..41d23cd7b 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBSCachingAllocator.cpp +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBSCachingAllocator.cpp @@ -138,6 +138,7 @@ class BSCachingAllocator : public CacheAllocator { } void empty_resource_pool() const { + std::lock_guard lk(mutex_); DIPU_DEBUG_ALLOCATOR( 8, "BSCachingAllocator::empty_resource_pool ,allocator:" << this); while (!async_mem_pool()->empty()) { @@ -180,6 +181,7 @@ class BSCachingAllocator : public CacheAllocator { void release_all_memory() const override { release_all_memory_impl(); } void flush_mem_pool() const { + std::lock_guard lk(mutex_); DIPU_DEBUG_ALLOCATOR( 8, "BSCachingAllocator::flush_mem_pool allocator:" << this); while (async_mem_pool()->ready()) {