static void wait_for_n_screens(strand self, struct layer *layer, float n_screens) { double distance = 0.; while (distance < (viewport_h * n_screens)) { float elapsed_time = strand_yield(self); distance += layer->speed * elapsed_time; } }
static void simple_ab() { struct bit { uint64_t *p; bool v; }; int fn_bit(strand self, void *bit_) { struct bit *bit = (struct bit *)bit_; for (int i = 0; i < 32; ++i) { *bit->p = (*bit->p << 1) | bit->v; strand_yield(self); } return 1; } strand a, b; uint64_t bits = 0; bool a_done, b_done; note("alternate between two functions"); a = strand_spawn(fn_bit, &(struct bit){ .p = &bits, .v = 0}, 128);
static void wait_for_elapsed_time(strand self, float goal) { double accum = 0.; while (accum < goal) accum += strand_yield(self); }