Skip to content

Instantly share code, notes, and snippets.

@josejuan
Last active August 29, 2015 13:56
Show Gist options
  • Save josejuan/8924708 to your computer and use it in GitHub Desktop.
Save josejuan/8924708 to your computer and use it in GitHub Desktop.
static int fibonacci(SyncLink s, int n, Action<int> action) {
Thread.Sleep(1000); // para ver cómo procesos rápidos esperan a otros lentos
if(n < 2)
return s.End(() => action(n), () => 1);
else
return s.Fork(() => action(n)
, ss => fibonacci(ss, n - 1, action)
, ss => fibonacci(ss, n - 2, action)
, (a, b) => a + b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment