'How to sync start of two cyclic tasks (swift)
I have two loops that must run periodically.
One of the loop (A) has a constant duration and is scheduled with high accuracy, no problem.
The other loop (B) can have a variable duration. Much shorter or much longer than duration of A. But whatever B’s duration, I want to start next B cycle at the start of the next A cycle. If B is much shorter than A, then it must wait next A’start. If B is much longer than A, then, when it completes, whatever the number of A cycles that occurred, it shall wait and start at next A’s start.
I first thought of using a semaphore. A would signal the semaphore at its start, while B would wait for it at it start. This works if B is shorter than A.
But if B is longer, the semaphore gets increment (maybe over 1), and I don’t get B to wait, it restarts immediately at its end and starts-sync is lost.
Any solution (preferably with GCD, but any solution would do) ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
