sharplet / EnumeratorKit

Ruby-style enumeration in Objective-C.
MIT License
69 stars 8 forks source link

Deadlock when repeatedly calling operators implemented in terms of EKEnumerator in a tight loop #19

Open sharplet opened 9 years ago

sharplet commented 9 years ago

EKFiber is implemented in a fairly heavyweight fashion in terms of NSOperationQueue and GCD semaphores. When a lot of fibers are created and completed within a tight loop, eventually a limit is reached where the system deadlocks. There are usually ~65 blocked operations when the deadlock occurs.

I've done a bunch of refactoring of EKFiber and its callers in this branch. Even moving from the current design (one NSOperationQueue per EKFiber) to a much simplified one (a single global NSOperationQueue for all EKFiber instances) doesn't resolve the problem. So the deadlock seems to be caused by the way semaphores are used to suspend execution.

The real solution is likely going to be switching to a lighter-weight concurrency model based on coroutines. Here are some possibilities I've found after some quick research:

sharplet commented 9 years ago

Learned about coroutines in libmill when reading about Venice. Looks promising.