Skip to content

Commit 5e279d4

Browse files
committed
Add comments about multi-threading
1 parent 7ea639f commit 5e279d4

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

cpp/src/arrow/memory_pool.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ class ARROW_EXPORT ProxyMemoryPool : public MemoryPool {
247247
};
248248

249249
/// EXPERIMENTAL MemoryPool wrapper with an upper limit
250+
///
251+
/// Checking for limits is not done in a fully thread-safe way, therefore
252+
/// multi-threaded allocations might be able to go successfully above the
253+
/// configured limit.
250254
class ARROW_EXPORT CappedMemoryPool : public MemoryPool {
251255
public:
252256
CappedMemoryPool(MemoryPool* wrapped_pool, int64_t bytes_allocated_limit)
@@ -256,6 +260,11 @@ class ARROW_EXPORT CappedMemoryPool : public MemoryPool {
256260
using MemoryPool::Reallocate;
257261

258262
Status Allocate(int64_t size, int64_t alignment, uint8_t** out) override {
263+
// XXX Another thread may allocate memory between the limit check and
264+
// the `Allocate` call. It is possible for the two allocations to be successful
265+
// while going above the limit.
266+
// Solving this issue would require refactoring the `MemoryPool` implementation
267+
// to delegate the limit check to `MemoryPoolStats`.
259268
const auto attempted = size + wrapped_->bytes_allocated();
260269
if (ARROW_PREDICT_FALSE(attempted > bytes_allocated_limit_)) {
261270
return OutOfMemory(attempted);

0 commit comments

Comments
 (0)