I play with Cilk and I have a printing problem synchronously. Printing is slow, so itβs hard to keep synchronous prints. For instance...
void ftn(int x)
{
if (x % 2 == 0)
{
std::cout << "printing.. " << x << std::endl;
}
else
{
cilk_spawn ftn(x/2);
cilk_spawn ftn(x++);
cilk_spawn ftn(x*x);
cilk_sync;
}
}
For the most part, printing is fine. However, it sometimes fails, and a second print statement from another thread runs in the middle of one thread print report.
How do you do C / Cilk printing inline? How can I guarantee that they remain synchronous?
source
share