I need to create a socket pool that will be served by multiple worker threads. Is there an implementation of a streaming pool of objects with functionality similar to Apache Commons' GenericObjectPool?
GenericObjectPool
Check out boost . flyweight .
I usually use TBB to implement thread-safe scalable pools.
template <typename T> class object_pool { std::shared_ptr<tbb::concurrent_bounded_queue<std::shared_ptr<T>>> pool_; public: object_pool() : pool_(new tbb::concurrent_bounded_queue<std::shared_ptr<T>>()){} // Create overloads with different amount of templated parameters. std::shared_ptr<T> create() { std::shared_ptr<T> obj; if(!pool_->try_pop(obj)) obj = std::make_shared<T>(); // Automatically collects obj. return std::shared_ptr<T>(obj.get(), [=](T*){pool_->push(obj);}); } };
, , Poco (Portable Components - ++-).
Poco::ObjectPool - . . , factory, , , .
Poco::ObjectPool
, . Poco , . borrowObject() -, .
borrowObject()