Skip to content

Instantly share code, notes, and snippets.

@stelleg
Created June 5, 2018 21:46
Show Gist options
  • Save stelleg/adccb6f8d6fc5f21dcefd225ded983bb to your computer and use it in GitHub Desktop.
Save stelleg/adccb6f8d6fc5f21dcefd225ded983bb to your computer and use it in GitHub Desktop.
sinc example
#include <qthread/qthread.h>
#include <qthread/sinc.h>
typedef struct args {
int i;
qt_sinc_t* sinc;
} args;
aligned_t hello(void* arg){
args a = *(args*)arg;
printf("hello world from thread %d\n", a.i);
qt_sinc_submit(a.sinc, NULL);
return 0;
}
void forall(qthread_f f, size_t n){
qt_sinc_t *sinc = qt_sinc_create(0, NULL, NULL, 0);
for(int i=0; i<n; i++){
args a = { i, sinc };
qt_sinc_expect(sinc, 1);
qthread_fork_copyargs(f, (void*)&a, sizeof(args), NULL);
}
qt_sinc_wait(sinc, NULL);
}
int main(){
qthread_initialize();
forall(hello, 10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment