Fiber creation. This program will print:
fiber_vv()
fddd is not valid yet
fiber_ddd(3, 4) = 7
fddd = 7
fiber_ddd(1, 2) = 3
fiber_vii(3, 14)
fiber_vi(42)
fiber_vv()
Note that the order of the last four lines is not deterministic.
#include <cstdio>
void fiber_vv();
void fiber_vv()
{
printf("fiber_vv()\n");
}
void fiber_vi(int i)
{
printf("fiber_vi(%d)\n", i);
}
void fiber_vii(int x, int y)
{
printf("fiber_vii(%d, %d)\n", x, y);
}
double fiber_ddd(double a, double b)
{
double res = a + b;
printf("fiber_ddd(%g, %g) = %g\n", a, b, res);
return res;
}
#if __cplusplus >= 201103L
double fiber_ddddi(double a, double b, double c, int d)
{
double res = a * b + c - d;
printf("fiber_ddddi(%g, %g, %g, %d) = %g\n", a, b, c, d, res);
return res;
}
#endif
{
fiber_vv();
fiber_ddd_future fddd =
async fiber_ddd(3, 4);
printf("fddd is %s\n", fddd->valid() ? "valid" : "not valid yet");
fddd->wait();
printf("fddd = %g\n", fddd->value());
#if __cplusplus >= 201103L
async fiber_ddddi(4, 5, 6, 7);
#endif
return 0;
}
int main_fiber(int argc, char **argv)
#define zth_fiber_define(...)
Do the definition part of zth_fiber() (to be used in a .cpp file).
#define zth_fiber(...)
Prepare every given function to become a fiber by async.
#define zth_fiber_declare(...)
Do the declaration part of zth_fiber() (to be used in an .h file).
#define async
Run a function as a new fiber.