Implementing connection pooling for a ThreadPool


#1

Hi Guys.

I want to use a pool of Libcurl handles for my ThreadPoolJobs.
So I thought about creating a wrapper class LibCurlHandle which is a ReferenceCountedObject.
Then I will have a LibCurlHandleArray of type ReferenceCountedArray with a CriticalSection to hold the handles.

Now It gets trickier:

Each time a ThreadPoolJob needs a handle it iterates the array looking for an object with getReferenceCount () == 1 and sets
it’s pointer to this object, when a ThreadPoolJob finish using this handle it removes it from the array and puts it again in the start
(for better searching next time)

If a ThreadPoolJob unexpectedly goes to heaven then I don’t loose the handle because of the reference counting.

Too crazy? know a better way? I’ll be happy to hear your comments.

Thanks


#2

[quote]If a ThreadPoolJob unexpectedly goes to heaven then I don’t loose the handle because of the reference counting.
[/quote]

yeah… that’s never a good approach to use when developing. If one of your threads blows up, you have to assume that your entire program is now compromised, and almost always the best response is for it to just crash, rather than struggling on with possibly corrupted data and code.


#3

OK, then in that case I’ll just revert into using a queue ( Array<LibCurlHandle, HTTPCriticalSection> )
and popping handles in the ThreadPoolJob() and pushing them again in ~ThreadPoolJob()

Jules I hold you responsible for handle leaks caused by blown up jobs :slight_smile:

Thanks.