Find a way to keep a global counter variable
Rather than yielding each time we reach an instrumented location (e.g. "end of a loop"), we'd rather like to yield every once in a while. This can be achieved e.g. by keeping a global state; for instance a counter that is incremented each time, and having the thread yield whenever the counter reaches a certain threshold.