My program is a server which handles incoming requests. Each valid request is wrapped in NSOperation
and passed to a normal NSOperationQueue
.
Each NSOpearation
processes its request. In some cases, there is contention at a NSDictionary
which I use dispatch_queue
(concurrent queue), dispatch_barrier_async
(when set value) and dispatch_sync
(when get value) to make this NSDictionary
thread-safe.
I test my program with 100 requests concurrently then the process freezes sometimes. I kill the process with SIGSEGV
to see crash log.
Most of the threads stuck at dispatch_sync
of this queue. And there is a note below
Dispatch Thread Soft Limit Reached: 64 (too many dispatch threads blocked in synchronous operations)
What does this note really mean? What is its behavior? I cannot find information about this limit. How can I fix this issue?
I can think of 2 possible ways to avoid this problem. (which I'm going to test them and will update later)
- Use
dispatch_semaphore
to limit submitting the block to this concurrent queue. - Limit
maxConcurrentOperationCount
of theNSOperationQueue
Do you have a better solution?