Skip to content

Instantly share code, notes, and snippets.

@newhouseb
Created July 12, 2010 14:47
Show Gist options
  • Save newhouseb/472556 to your computer and use it in GitHub Desktop.
Save newhouseb/472556 to your computer and use it in GitHub Desktop.
Generator pattern with only pthreads and macros (generator.h is ~80 LOC - will publish after some cleaning)
#include <stdio.h>
#include "generator.h"
generator(int, counter, int start; int other)
{
while(1) {
yield(arguments.start++);
yield(arguments.other);
}
}
int main() {
counter * gen = create_generator(counter, 44, 72);
for (int i = 0; i < 10; i++) {
printf("count: %i\n", gen->next());
}
return 0;
}
_Output_______________________
count: 44
count: 72
count: 45
count: 72
count: 46
count: 72
count: 47
count: 72
count: 48
count: 72
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment