bundle - create an empty coroutine bundle in user-supplied memory
int bundle_mem(void *mem);
Coroutines are always running in bundles. Even coroutine created by go() gets its own bundle. Bundle is a lifetime control mechanism. When it is closed all coroutines within the bundle are canceled.
This function creates an empty bundle. Coroutines can be added to the bundle using bundle_go() and bundle_go_mem() functions.
mem is the memory of at least BUNDLE_SIZE bytes to store the bundle in. The memory must not be deallocated before all handles referring to the bundle are closed with the hclose() function, or the behavior is undefined.
Do not use this function unless you are hyper-optimizing your code and you want to avoid a single memory allocation per bundle. Whenever possible, use bundle() instead.
If hdone() is called on the bundle it waits while all coroutines exit. After calling hdone(), irrespective of whether is succeeds or times out, no further coroutines can be launched using the bundle.
When hclose() is called on the bundle all the coroutines contained in the bundle will be canceled. In other words, all the blocking functions within the coroutine start failing with ECANCELED error. The hclose() function itself won't exit until all the coroutines in the bundle exit.
Returns a handle to the bundle. In the case of an error, it returns -1 and sets errno to one of the values below.
char mem[BUNDLE_SIZE]; int b = bundle_mem(mem); bundle_go(b, worker()); bundle_go(b, worker()); bundle_go(b, worker()); msleep(now() + 1000); /* Cancel any workers that are still running. */ hclose(b);