11 const struct Vertices *vertices;
12 Computation *separately;
17 ForAllThreads *allthreads;
24 static void *routine(void *thread_v) {
25 PerThread *t= thread_v;
26 ForAllThreads *a= t->allthreads;
28 a->separately(a->vertices, t->section, t->secdata, a->gendata);
34 void inparallel(const struct Vertices *vertices,
35 Computation *separately,
37 size_t secdatasz, void *gendata) {
38 typedef struct { unsigned char secdata[secdatasz]; } SecData;
40 ForAllThreads allthreads;
41 SecData secdatas[nsections];
43 allthreads.vertices= vertices;
44 allthreads.separately= separately;
45 allthreads.gendata= gendata;
48 PerThread threads[nsections];
51 for (s=0; s<nsections; s++) {
52 threads[s].allthreads= &allthreads;
53 threads[s].section= s;
54 threads[s].secdata= secdatas[s].secdata;
55 r= pthread_create(&threads[s].thread,0,routine,&threads[s]);
56 if (r) diee("pthread_create");
59 for (s=0; s<nsections; s++) {
60 r= pthread_join(threads[s].thread, 0);
61 if (r) diee("pthread_join");
62 combine(vertices, s, threads[s].secdata, gendata);
65 separately(vertices, 0, &secdatas[0], gendata);
66 combine(vertices, 0, &secdatas[0], gendata);