diff --git a/paddle/fluid/distributed/service/communicator.h b/paddle/fluid/distributed/service/communicator.h index 9caec79e58b01b08bd13493e23efaee4fb437463..c6d37defbd626b553f141f94a1325209b6a1834c 100644 --- a/paddle/fluid/distributed/service/communicator.h +++ b/paddle/fluid/distributed/service/communicator.h @@ -61,7 +61,11 @@ using Variable = framework::Variable; template class BlockingQueue { public: - explicit BlockingQueue(size_t capacity) : capacity_(capacity) {} + explicit BlockingQueue(size_t capacity) : capacity_(capacity) { + PADDLE_ENFORCE_GT(capacity_, 0, + platform::errors::InvalidArgument( + "The capacity must be greater than 0.")); + } bool Push(const T &elem) { std::unique_lock lock(mutex_);