Created
March 13, 2012 11:26
-
-
Save faithandbrave/2028205 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "continuation.hpp" | |
void amb1_f(continuation& cont) | |
{ | |
cont.suspend(1); | |
cont.suspend(2); | |
cont.suspend_break(3); | |
} | |
void amb2_f(continuation& cont) | |
{ | |
cont.suspend(4); | |
cont.suspend_break(5); | |
} | |
int main() | |
{ | |
continuation amb1(amb1_f); | |
continuation amb2(amb2_f); | |
int x = amb1.resume(); | |
int y = amb2.resume(); | |
while (true) { | |
std::cout << x << "," << y << std::endl; | |
if (amb2.is_complete()) { | |
if (amb1.is_complete()) { | |
break; | |
} | |
x = amb1.resume(); | |
y = amb2.restart(); | |
} else { | |
y = amb2.resume(); | |
} | |
} | |
} | |
/* | |
output: | |
1,4 | |
1,5 | |
2,4 | |
2,5 | |
3,4 | |
3,5 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment