Skip to content

Instantly share code, notes, and snippets.

@faithandbrave
Created March 13, 2012 11:26
Show Gist options
  • Save faithandbrave/2028205 to your computer and use it in GitHub Desktop.
Save faithandbrave/2028205 to your computer and use it in GitHub Desktop.
#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