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.