I implemented Thread pooling using NSOperationQueue
. In which i set maxConcurrentOperationCount
to 25
. i.e. concurrently 25 threads are running at a time.
I am uploading chunks to a server by using this NSOperationQueue
. So chunks are allocated to the first 25 threads. After the NSOperationQueue
is full, I want to pause the chunking reading part, then whenever threads from the queue complete, resume the chunking part to allocate new threads to NSOperationQueue
to replace the thread which complete.
My Code:
NSOperationQueue *operationQueue = [NSOperationQueue new];
operationQueue.maxConcurrentOperationCount=5;
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(upload:) object:f_objChunkDetails->FileStream];
NSUInteger oprCnt=operationQueue.operationCount;
if(oprCnt >= 5) {
// wait till queue has a free slot
} else {
[operationQueue addOperation:operation];
}
So how to pause and resume is used in NSOperationQueue
? How to implement ManualResetEvent
in Objective-C?