void *worker (void *arg) { .... (You will need to convert arg to the correct type before you can use the value passed) .... } int main(int argc, char *argv[]) { // SEQUENTIAL Section .... Prepare problem (setup shared variables) .... // PARALLEL Section // Start the worker threads for (i = 0; i < NUM_PROCESSORS; i = i + 1) { param[i] = ....; pthread_create(&tid[i], &attr, worker, & param[i]) } // Wait for all workers to finish for (i = 0; i < NUM_PROCESSORS; i = i + 1) pthread_join(tid[i], NULL); // SEQUENTIAL Section .... Post process results from workers.... (Or start another prepare section followed by a parallel + join section) } |
Note:
|
|
|
because:
You will see in the demo programs that the data that need to be processed are stored in a global variabel
You do this, so that:
|
|