11 const struct Vertices *vertices;
12 Computation *separately;
17 ForAllThreads *allthreads;
23 static void *routine(void *thread_v) {
24 PerThread *t= thread_v;
25 ForAllThreads *a= t->allthreads;
27 a->separately(a->vertices, t->section, t->secdata, a->gendata);
32 void inparallel(const struct Vertices *vertices,
33 Computation *separately,
35 size_t secdatasz, void *gendata) {
36 typedef struct { unsigned char secdata[secdatasz]; } SecData;
38 ForAllThreads allthreads;
39 SecData secdatas[nsections];
40 PerThread threads[nsections];
44 allthreads.vertices= vertices;
45 allthreads.separately= separately;
46 allthreads.gendata= gendata;
48 for (s=0; s<nsections; s++) {
49 threads[s].allthreads= &allthreads;
50 threads[s].section= s;
51 threads[s].secdata= secdatas[s].secdata;
52 r= pthread_create(&threads[s].thread,0,routine,&threads[s]);
53 if (r) diee("pthread_create");
56 for (s=0; s<nsections; s++) {
57 r= pthread_join(threads[s].thread, 0);
58 if (r) diee("pthread_join");
59 combine(vertices, s, threads[s].secdata, gendata);